C geeks?

Aug 15, 2008 17:56

I am writing a program that takes a decimal number and converts it to hex. The input can be int or float. Now, I got it to convert int to hex but I can't convert the float to hex. It's dropping the fraction completely and just using whatever is to the left of the decimal point.
any suggestions?

Leave a comment

Comments 7

brucix August 16 2008, 01:13:50 UTC
What do you want the hex representation to look like? If I type 11.11, do you want it to convert to a.a?

If so, separate the float into 2 parts, the integer part and the fractional part, and multiply the fractional part by a large enough power of 10 to convert it to an integer, then convert both to hex and print them out appended with the decimal point in between.

Reply

brucix August 16 2008, 01:14:23 UTC
err, b.b

Reply

everanddespair August 16 2008, 01:35:01 UTC
No it's supposed to be IEEE Standard 754

Reply

brucix August 16 2008, 01:39:34 UTC
I found this guy's program with the googler: http://johnsantic.com/comp/float.html

Reply


two_star August 16 2008, 02:46:26 UTC
Do you want to format a float as a hexadecimal floating point number? So that 1.0e+13 would come out as the string "9.184E73e+A"? (This seems like a weird thing to want, and the 'e's are ambiguous.)

Reply

everanddespair August 16 2008, 03:22:01 UTC
no like, using an int as an example, 123 would be 0x7b in hex.

Reply


Leave a comment

Up