[Math] Convert hexadecimal numbers to floating-point format using single-precision IEEE 754 format

binaryfloating point

I need help with converting hexadecimal numbers to floating-point format using single-precision IEEE 754 format.

Hex numbers such as 312A. how do I go about converting it?

I know how to convert from decimal to floating-point format using single-precision IEEE 754 format. However, do now know how to do hexadecimal. I converted it into binary which is

0 0011 0001 0010 1010

Need hep, please.

Best Answer

Binary is easier than decimal for this.

The IEEE-754 32-bit float format is a sign bit as bit 31, followed by an 8-bit exponent offset by 127 in bits 30-23, followed by 23 bits of mantissa in bits 22-0. But the mantissa has a suppressed leading 1.

Let's do this for the number hex 312A = binary 0000 0000 0000 0000 0011 0001 0010 1010. It is positive, so the lead bit of the representation will be 0.

The most significant non-zero bit is the 1 in bit 13, so the mantissa is 127+13 = 10001101.

The mantissa is the rest of the number, dropping that leading 1, thus 1 0001 0010 1010. We fill the rest of the least significant bits with 0.

So the representation will be 0 10001101 1000100101010 0000000000 or writing it in groups of 4 bits, 0100 0110 1100 0100 1010 1000 0000 0000 = 46C4A800

(The above ignores special values, which have the exponent at 11111111 -- infinty and Not-a-number -- or at 00000000 -- zero or "denormalized numbers).