Algorithms on converting hex to IEEE-754 single-precision floating point number

57 Views Asked by At

I need help with finding algorithm converting hex to IEEE-754 single-precision floating point number (without coding). I couldn't find any on the internet :(

For example, given input string 0xB9CD542, we need to return string 0x1.39aa84p-104 where last number is in hexadecimal exponential form (single precision floating point number) rounded to 0

1

There are 1 best solutions below

1
On

OK, I'll bite:

If 0xB9CD54 (binary 00000000101110011100110101010100) is an IEEE-754 single-precision number, then it can be decomposed as follows:

Sign bit = 0, so number is positive
Biased exponent = 00000001, so unbiased exponent is -126
Mantissa (including implied leading 1) = 101110011100110101010100 = 0xB9CD54

Shifting the mantissa left by 1 so that it starts with 1. gives 1.739AA8.

So we end up with 0x1.739AA8p-126.

Conversely, the decimal form of 0x1.39aa84p-104 would seem to be 0xb9CD542 according to this site. So it looks like you need to check your sources!