Convert ieee 754 float to hex with c - printf

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-05-31T02:27:12Z Indexed on 2010/05/31 2:32 UTC
Read the original article Hit count: 454

Filed under:
|
|

Ideally the following code would take a float in IEEE 754 representation and convert it into hexadecimal

void convert() //gets the float input from user and turns it into hexadecimal { float f; printf("Enter float: "); scanf("%f", &f); printf("hex is %x", f); }

I'm not too sure what's going wrong. It's converting the number into a hexadecimal number, but a very wrong one.

123.1443 gives 40000000 43.3 gives 60000000 8 gives 0

so it's doing something, I'm just not too sure what.

Help would be appreciated

© Stack Overflow or respective owner

Related posts about c

    Related posts about floating-point