Converting Hex to Decimal

hi,
I want to convert my hex value to decimal. How can I do this? help me pls.
Suku

actually...the hardware I'm interacting through com port will retrun data every time in different length. I'm reading that data, byte by byte only. So in that second byte I'm getting the length of the data returned by the hardware. Now for executing my loop that length is required.
while ((ch = (byte)portInStream.read())!=-1)
indata[i] = ch;
String hexString = Integer.toHexString(indata);
hexDec = Integer.parseInt(hexString);
strData =strData + hexString;
i++;
if(i==15) break;
in the above code I'm reading 15 bytes from the port. But it may vary...to know the length I want to convert the second byte to int.

Similar Messages

  • Convert hex to Decimal and keep leading zeros..

    Hi,
    I hope you can help?
    How to convert hex to Decimal and keep leading zeros
    I read 002C, hex, and I want to convert it to 0044 decimal.
    sscanf (MyNum, "%4x", &DecNum); will only give me 44.
    It have been working up till I started to get leading zeros.
    We will always have a 4 digit hex input in a range
    We must have the leading 00 in this case.
    How is this best done?
    Thanks for the help
    Simon
    Solved!
    Go to Solution.

    Hi,
    I don't really understand your problem. Is this stuff what you need ?
    int main (int argc, char *argv[])
    const char MyNum[] = "002C";
    int DecNum;
    sscanf (MyNum, "%4x", &DecNum);
    printf ("%04d", DecNum);
    getchar ();
    return 0;
    "0044" appears on standard output when printf function executes...

  • Formula to convert Hex to Decimal

    Hello All,
    I have "upgraded" from AppleWorks to iWork Numbers. Yes I've read all about how somethings didn't get ported over, etc. What I need is a formula to convert base 16 to base 10. Any ideas how to do this? I see that numbers has a formula editor so is it possible to make up a conversion formula? Someone done this who would like to share?
    Thanks,
    Dan

    Dan,
    Here's a brute-force solution. There may be more elegant ones out there.
    DEC formula is: =IF(ISERROR(LOOKUP(MID(A2, 1, 1), LOOKUP TBL :: A$1:A$16, LOOKUP TBL :: B$1:B$16) * 16^3+LOOKUP(MID(A2, 2, 1), LOOKUP TBL :: A$1:A$16, LOOKUP TBL :: B$1:B$16) * 16^2+LOOKUP(MID(A2, 3, 1), LOOKUP TBL :: A$1:A$16, LOOKUP TBL :: B$1:B$16) * 16+LOOKUP(MID(A2, 4, 1), LOOKUP TBL :: A$1:A$16, LOOKUP TBL :: B$1:B$16)),"", LOOKUP(MID(A2, 1, 1), LOOKUP TBL :: A$1:A$16, LOOKUP TBL :: B$1:B$16) * 16^3+LOOKUP(MID(A2, 2, 1), LOOKUP TBL :: A$1:A$16, LOOKUP TBL :: B$1:B$16) * 16^2+LOOKUP(MID(A2, 3, 1), LOOKUP TBL :: A$1:A$16, LOOKUP TBL :: B$1:B$16) * 16+LOOKUP(MID(A2, 4, 1), LOOKUP TBL :: A$1:A$16, LOOKUP TBL :: B$1:B$16))
    Be sure to Format Col A of both tables to Text.
    Regards,
    Jerry

  • Java code to convert - Hex to Dec

    I'ld like to convert an Integer or a String from hexadecimal format to a decimal format;
    For example: 30 give 0; 50 give P and so on.
    Can any one help me sending to me a java code that do it please?
    Thanx a lot

    This doesn't convert hex to decimal, but it does convert hex to the character representation, which is what it sounds like you want. At any rate, given "30" it will print "0" and given "50" it will print "P". Also, given "P" it will print "is invalid".
            try
                int in = Integer.parseInt(s, 16);
                Character ch = new Character((char)in); // should validate range here
                System.out.println("In: " + s + ", out: " + ch);
            catch (NumberFormatException e)
                System.out.println("In: " + s + " is invalid.");
            }

  • Conersion of hex to decimal

    Hi,
    I am getting a problem. I am trying to convert hex to decimal but the hex number is pretty huge..
    Can anyone suggest a solution.
    DATA: X00(32) TYPE X VALUE
    '00200120022003200420052006200720082009200A200B200C200D200E200F20'.

    Hi,
    Check this,
    DATA :
      in_buffer  TYPE xstring,
      out_buffer TYPE xstring,
      conv       TYPE REF TO cl_abap_conv_in_ce.
    in_buffer =
    '00200120022003200420052006200720082009200A200B200C200D200E200F20'.
    conv = cl_abap_conv_in_ce=>create(
    encoding = 'UTF-8'
    endian = 'L'
    input = in_buffer
    CALL METHOD conv->read(
    EXPORTING n = 5
    IMPORTING data = out_buffer
    WRITE out_buffer.
    Regards
    Adil

  • Convertion Hex String to 32bits Decimal floating point??

    Hi,
    I would like to know how to convert hexa like: 416b0ac3 in decimal 32bits floating-point. The result of this string is suppose to be 14.690127.
    So i must be able to do:
    From 32-bit Hexadecimal Representation To Decimal Floating-Point
    Thanks for your support
    RiderMerlin

    RiderMerlin
    You can use the typecast function to do this.
    David
    Message Edited by David Crawford on 09-06-2006 03:31 PM
    Attachments:
    Typecast to Single.jpg ‏6 KB

  • Checking and Converting binary, octal, decimal, and hex

    Hi,
    I have a classroom project which will need to validate that data entered in a text is of a certain type with a keyListener, and then convert that value to the other 3 types.
    I know character.isDigit will handle the decimal case, and that I can then use Integer.otString methods to convert to binary, octal, and hex, but what about the other cases?
    Thanks

    OK, this isn't working. If I've already established
    that the string entered into, for example, the
    integer-only textfield is a valid integer, I should be
    able to simply use integer.parseint(s, 2) to convert
    it into binary, right?Not exactly. You should be able to use Integer.parseInt(s, 2) to return the result of converting it from binary representation. You appear to think that this affects whatever "s" refers to, which is not the case. Note also, that method returns an int which is the decimal value in question.
    When you are thinking of int variables, be careful not to think of them as "decimal" or "binary". They are neither. They are just numbers. "Decimal" and "binary" are text representations of numbers, so those concepts can only be applied to strings.
    Integer.parseInt(s, 2);
    txtBin.setText(s);So here you want to assume that the input is a string that represents a number in decimal, and you want to find the string that represents the number in binary. Like this:// convert string in decimal representation to number
    int dec = Integer.parseInt(s);
    // convert int to binary representation as string:
    String binary = Integer.toBinaryString(dec);
    // write that to the text field
    txtBin.setText(binary);You could use a one-liner to do that, but you'll need the "dec" variable to set the other text boxes.
    Rembering why I hate OO...All of what I said there is true in just about all computer languages, OO or otherwise.
    PC²

  • Hex to decimal

    there is any function to convert from hex to decimal and vis versa in PL/SQL?
    Regeards
    eng. Amn2000

    create or replace function sf_sys_hex_to_dec (
    p_hexadecimal in varchar2
    ) return number as
    v_character varchar2(1);
    v_decimal number(10);
    v_number pls_integer;
    v_position pls_integer;
    v_length pls_integer;
    begin
    if p_hexadecimal is null then
    sp_sys_internal_error('Hexadecimal value cannot be null.');
    end if;
    v_length := length(p_hexadecimal);
    if v_length > 8 then
    sp_sys_internal_error('Hexadecimal value too big - maximum allowed is "FFFFFFFF".');
    end if;
    v_position := v_length;
    v_decimal := 0;
    loop
    v_character := substr(p_hexadecimal,v_position,1);
    if v_character = '0' then
    v_number := 0;
    elsif v_character = '1' then
    v_number := 1;
    elsif v_character = '2' then
    v_number := 2;
    elsif v_character = '3' then
    v_number := 3;
    elsif v_character = '4' then
    v_number := 4;
    elsif v_character = '5' then
    v_number := 5;
    elsif v_character = '6' then
    v_number := 6;
    elsif v_character = '7' then
    v_number := 7;
    elsif v_character = '8' then
    v_number := 8;
    elsif v_character = '9' then
    v_number := 9;
    elsif v_character = 'A' then
    v_number := 10;
    elsif v_character = 'B' then
    v_number := 11;
    elsif v_character = 'C' then
    v_number := 12;
    elsif v_character = 'D' then
    v_number := 13;
    elsif v_character = 'E' then
    v_number := 14;
    elsif v_character = 'F' then
    v_number := 15;
    else
    sp_sys_internal_error('Invalid hexadecimal character found.');
    end if;
    v_decimal := v_decimal + v_number * 16 ** (v_length - v_position);
    v_position := v_position - 1;
    if v_position = 0 then
    exit;
    end if;
    end loop;
    return(v_decimal);
    end;
    create or replace function sf_sys_dec_to_hex (
    p_decimal in number
    ) return varchar2 as
    v_hexadecimal varchar2(8);
    v_character varchar2(1);
    v_number pls_integer;
    v_integer pls_integer;
    v_module pls_integer;
    v_first_time boolean;
    begin
    if p_decimal is null then
    sp_sys_internal_error('Decimal value cannot be null.');
    end if;
    if p_decimal > 4294967295 then
    sp_sys_internal_error('Decimal value too big - maximum value is 4294967295.');
    end if;
    v_first_time := true;
    v_number := p_decimal;
    loop
    v_integer := trunc(v_number / 16);
    v_module := mod(v_number,16);
    if v_module = 0 then
    v_character := '0';
    elsif v_module = 1 then
    v_character := '1';
    elsif v_module = 2 then
    v_character := '2';
    elsif v_module = 3 then
    v_character := '3';
    elsif v_module = 4 then
    v_character := '4';
    elsif v_module = 5 then
    v_character := '5';
    elsif v_module = 6 then
    v_character := '6';
    elsif v_module = 7 then
    v_character := '7';
    elsif v_module = 8 then
    v_character := '8';
    elsif v_module = 9 then
    v_character := '9';
    elsif v_module = 10 then
    v_character := 'A';
    elsif v_module = 11 then
    v_character := 'B';
    elsif v_module = 12 then
    v_character := 'C';
    elsif v_module = 13 then
    v_character := 'D';
    elsif v_module = 14 then
    v_character := 'E';
    elsif v_module = 15 then
    v_character := 'F';
    end if;
    if v_first_time = true then
    v_hexadecimal := v_character;
    else
    v_hexadecimal := v_character| |v_hexadecimal;
    end if;
    if v_integer = 0 then
    exit;
    end if;
    v_number := v_integer;
    v_first_time := false;
    end loop;
    return(v_hexadecimal);
    end;
    null

  • Converting character to decimal format

    hi
    i am working on a development where the selection screen has date and time as select options.
    and based on the input i have to concatenate date and time into the format- DD.MM.YYY HH.MM.SS
    there is a value in the table that has a field containing the above value and i have to fetch the data based on this input.
    Now the problem is the field in the table is of format DECIMAL of 16 length.
    i want to know how can i pass this value to the select statement.
    thanks in advance

    Hi ,
    Please check the blog on the below link.
    [Re: Converting char to decimal value format as defined in SU3(User profile);
    This will solve your query.
    Regards
    Abhii......

  • How to convert string to decimal in data association function?

    In a BPM Script component, how in the Data Association can I use an expression to convert an argument from String to Decimal?  I have a Process argument named percentage which is a string.  I need to set the value of a data object called signed to either "Y" or "N" based on the percentage being greater than 0.4.  Something like this:
    (percentage > 0.4) ? "Y" : "N"
    The problem here is that percentage is a string, so must be converted to a decimal value before the compare will work.  I cannot find a function that allows that.  I need something like parseDecimal(percentage), but the Expression Builder does not offer that for a string using a Simple Expression.
    If it cannot be converted, is there another way to do this?

    Guessing you figured this out on your own, but if you wanted to use a Script activity one way to do what you want is when you're creating your data associations drag the "Expression" icon in the middle and double click the icon in the middle you just added:
    Get out of the Simple expression mode and into the XPath expression mode by clicking the dropdown in the upper left corner -> click "XPath Exp".
    In the Functions dropdown on the right, click "Conversion Functions" -> click "number" and then insert it into the expression.
    In the Variables list, select your string variable and insert it into the number function so that it looks something like this:  number(bpmn:getDataObject('myStringVariable'))
    Click OK
    Click your expression icon in the middle and drag it over your decimal variable.
    To have it evaluate and return a Boolean expression in your Script activity, add a Boolean process variable and add an XPath expression as described above except have the logic be this:  number(bpmn:getDataObject('myStringVariable')) > .4  (the "greater than" shown above is added to the expression by clicking "Logical Functions" from the functions dropdown).  Click OK and drag your expression icon over your Boolean variable.
    Dan

  • Converting hex to dec

    Hi everybody,
    I want to join this two numbers and convert them from hex to dec. I have tried using joint and conversion but I still couldn't work it. In the following screen shot I took it suppose to be 3E8 in hex which equals to 1000 in dec. I need suggestion from you how to approach this.
    Thanks
    Solved!
    Go to Solution.

    SOBGA wrote:
    As I was reading all the answers about converting Hex to Dec,I found out that many of you are making it so complicated.To make it easier for a learner or beginner,this is what it takes:
    Open a blank VI
    Click on numeric control
    Right click on the same numeric control
    Scroll down to "Representation"
    Click on "U8"
    Go to numeric indicator and repeat step 4 and 5
    Then right click again on numeric control
    Scroll down to "Properties" and click
    Click on "Data entry",if necessary,change the minimum and maximum
    Pass to "Display format" 
    Click on "Hexadecimal" then you are done.The rest is to go on the block diagram to wire the numeric control to the numeric indicator and it works.
    You can do the same process reverse for dec to hex.But you must know that what we did for "numeric control" on (Hex to Dec) will be done to "numeric indicator" on (Dec to Hex).This same process can apply to octal and binary without the use of complicated array,string while loop and so on...
    I'm a beginner in Labview and I understand that you need to explain more to understand better.
    If you really read all of the comments, you would see that Altenbach already stated this (saying it is just a cosmetic property for the indicator).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Converting Hex to Integer Value

    I'm trying to convert hex code to the corresponding integer, which can then be used to display a character.
    For example I have the code.
    int i = 0xE7;
    System.out.println(i);
    System.out.write(i)This produces the output as expected with the first output outputting 231, and the second line outputting the corresponding character.
    My problem comes when trying to make it so the hex code is variable.
    For example, I receive an output of 7
    This output is then the last digit of the hex code (so i check if needs to be converted to a, b etc.) then try and combine it with the prefix 0xE to create the hex code.
    I'm not quite sure how to do this bit as I cant carry out
    num = 7;
    hex = "0xE"+num;
    int i = hex;as the last line doesn't calculate due to hex being a string.
    Many thanks for your help.

    leesto wrote:
    The char array is currently being created using:
    char [] hexchar = "0123456789ABCDEF".toCharArray();
    Look this is OK, you need to do nothing but just the following:
    // I am using the very first example you provided
    // i is the index for the char
    String hex = "0E" + hexchar;
    Integer.parseInt(hex, 16);
    System.out.println(i);

  • Convert  Hex to Dec in Numbers

    Hi,
    Can some one let me know how to Convert Hex to Dec in Numbers.
    When ever I type Hex 00E0 it will appear in the cell like this 0.00E+00 ,who do i fix this.
    Thanks
    Ashan

    -+-+-+-+-+-+-+-
    Entering the Help and Terms of Use area you will read:
    *What is Apple Discussions and how can it help me?* 

    Apple Discussions is a user-to-user support forum where experts and other Apple product users get together to discuss Apple products. … You can participate in discussions about various products and topics, find solutions to help you resolve issues, ask questions, get tips and advice, and more.
    _If you have a technical question about an Apple product, be sure to check out Apple's support resources first by consulting the application Help menu on your computer and visiting our Support site to view articles and more on our product support pages_.
    I have a question or issue—how do I search for answers? _
It's possible that your question or issue has already been answered by other members so do a search before posting a question._ On most Apple Discussions pages, you'll find a Search Discussions box in the upper right corner. Enter a search term (or terms) in the field and press Return. Your results will appear as a list of links to posts below the Search Discussions Content pane.
    -+-+-+-+-+-+-+-
    Taking care of that, you would already know the response.
    Using the really cumbersome keystring "convert AND hex" as described in the forum's help returns two entries.
    One is you question.
    The other is: http://discussions.apple.com/thread.jspa?messageID=7242325
    which gives a link to:
    http://discussions.apple.com/thread.jspa?messageID=7078123
    Yvan KOENIG (from FRANCE jeudi 24 juillet 2008 09:19:34)

  • Convert Mainframe Packed Decimal to Oralce Number Format

    Dear all,
    I am having a file in which amount fields are given in a Packed Decimal format. Can anyone suggest me how I can read this data element from the file and convert it into Oracle Number datatype.
    File is a fixed length. All the amount fields are given in Packed Decimal Format and rest of the fields are given in text format.
    Thanks and regards
    Nagasayan Puppala

    Hi,
    Firstly thanks for your reply.
    Actually I am not using SQL Loader to load data from
    a flat file to Oracle table. I am writing a custom
    program that reads the file and populates the oracle
    table. I'll put aside the question of 'why' you'd want to do that. SQL*Loader's singular purpose in life is to load flat files of data into Oracle DB. Sometimes there is a reason for reinventing the wheel.
    How does your program communicate with the Oracle DB? If utilizing ESQL and Pro*Cobol (or Pro*<whatever> ) you will have read the data into a variable of some type in you host language. The variable of the host variable to hold the value (if you did a 'select from' that table) would be the correct target type for an insert statement. Whatever host language type conversion is available bewteen those two types ( if they are different at all ) is all that is needed. The precompilers have converters between certain native host and internal Oracle types built-in. It is how you get any data between the two systems. This is only a problem if the host language has no converter between the numeric types (if differnet.). When you read from the flat file are you reading it into a native packed decimal in the host language?
    ODBC/JDBC similar strategy..... cast conversion between the native type that Oracle wants and the one into which your custom program reads it into.
    So I want to know whether there are any Oracle
    utility programs that will convert the packed decimal
    to a oracle number format or not.There are Oracle routines that convert into the native Oracle DB formats. There are implicitly available through the normally utilized interfaces to OCI ( ESQL and ODBC/JDBC ) . There are none decoupled from those interfaces though (that I know of).
    There are no standalone programs that mutate a flat file into another flat file that then could be loaded. That's is typically slower and utilzes more space than most customers want than just directly inputing the data into Oracle DB.
    Message was edited by:
    lytaylor

  • Property to set hex/binary/decimal format at run time?

    Hi, I'd like to allow my user to choose between hex/binary/decimal formats in his number input. I'm happy to do the radio button stuff and the code to "hear" what he wants, but I can't find a property of my variable which selects the format at run-time - there is of course the "Format & Precision..." which I can get at by right mouse click BEFORE running, so I know it's likely to be available at run-time. Any suggestions welcome. Thanks, Richard.

    It's not necessary to use property node because you can use the builtin
    property of the indicator.
    Click the rigth mouse button over the indicator and select show radix.
    On the left side of the indicator appear radix that you can push to choose
    between hex, binary, octal and decimal.
    Bye
    Golzio
    "R" ha scritto nel messaggio
    news:[email protected]..
    > Hi, I'd like to allow my user to choose between hex/binary/decimal
    > formats in his number input. I'm happy to do the radio button stuff
    > and the code to "hear" what he wants, but I can't find a property of
    > my variable which selects the format at run-time - there is of course
    > the "Format & Precision..." which I can get at by right mouse click
    > BEFORE run
    ning, so I know it's likely to be available at run-time. Any
    > suggestions welcome. Thanks, Richard.

Maybe you are looking for

  • "Ambiguous EUR/INR exchange rate relation "

    Hi All, While saving stock in "MB1C" I encounter an error "Ambiguous EUR/INR exchange rate relation " I have tried to post new exchange rate in "ob08" for "M" but its not serving the purpose. Plz help Regards

  • Leopard always boots into Safe Boot

    Every time I restart Leopard it boots into "Safe Boot" mode. To get it to boot into regular mode I have to keep hitting "x" after the startup sound while booting. I read that Leopard shouldn't boot into safe mode unless I hold down the shift key when

  • Safari won't close windows

    I work in a music technology lab and on 3 of G4 Imacs, Safari can not close its windows. What I mean is that when you click on the red circle or use command W, the windows won't close. The Imacs are using 10.4.2 and have 512megs of ram. The windows d

  • X99S XPOWER AC : USB 3 External Drive issue

    Hello team, If I want to copy files onto my USB3 drive windows hangs on "calculating.." Thi shappens with files larger than + - 120 mb.. I tried with my client pc and it worked. I on my sons socket 2011 pc ( USB 3) and it worked.B Reinstalled Window

  • I have CS4 Master Collection serial number, but only want to download Illustrator

    I have downloaded from Adobe's website Illustrator, but when I put in the serial number for my CS4 Master Collection, it comes back with serial number is invalid.