How to convert double to hex

Hey,
I am working on this project where I neeed to convert a double variable to a hex variable. I have searched on line and haven't got anything. Any help will be greatly appreciated.


Thanks In Advance
Only integer numbers can be represented as hex AFAIK. But OK, you do have 8 bytes there. You would reinterpret this double as a 64-bit integer and just get the HEX representation of this in-memory data. Is that what you are looking for?
Yes
Only integer numbers can be represented as hex AFAIK

Anything can be hex, it's just binary in some memory (AFAIK :) ).

This page looks pretty helpful:
http://babbage.cs.qc.cuny.edu/IEEE-754.old/Decimal.html

Although, a quote from here:
http://www.h-schmidt.net/FloatConverter/IEEE754.html

Conversion: The value of a IEEE-754 number is computed as:
sign * 2exponent * mantissa
The sign is stored in bit 32. The exponent can be computed from bits 24-31 by subtracting 127. The mantissa (also known as significand or fraction) is stored in bits 1-23. An invisible leading bit (i.e. it is not actually stored) with value 1.0 is placed in front, then bit 23 has a value of 1/2, bit 22 has value 1/4 etc. As a result, the mantissa has a value between 1.0 and 2. If the exponent reaches -127 (binary 00000000), the leading 1 is no longer used to enable gradual underflow.

Rounding errors: Not every decimal number can be expressed exactly as a floating point number. This can be seen when entering "0.1" and examining its binary representation which is either slightly smaller or larger, depending on the last bit.

Other representations: The hex representation is just the integer value of the bitstring printed as hex. Don't confuse this with true hexadecimal floating point values in the style of 0xab.12ef.


Don't know if this helps at all actually.
Last edited on
Topic archived. No new replies allowed.