1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Conversion of 2 hex numbers into 2 strings and then into a single float?

Discussion in 'C' started by polly123, Aug 17, 2009.

  1. polly123

    polly123 New Member

    Joined:
    Aug 17, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    I need some simple advice...:embarasse

    I have a hexadecimal number that is created by two variables, num and dec. where num represent values 0-360 while dec are the decimal values 0-99. The most significant bits are not used in each numbers so I cut these off. For example, if num is f010 and dec = fe02 it means that the total number is 10.02. To print this out I do the following:
    sprintf (buff1, "%x", *num);
    sprintf (buff2, "%x", *dec);
    printf("whole number: %s.%s ", buff1+(strlen(buff1)-3), buff2+(strlen(buff2)-2));
    >> whole number: 010.02
    Now my problem is to take this number 10.02 and add it to another number.
    What is the easiest way to convert this into a float?

    I’ve been trying different things but none of them have worked out well. I would be grateful for any input.
    -Polly
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    float f=(num & 0xff) + float(dec & 0xff)/100.0;
     

Share This Page