1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Well, convert hexadecimal to decimal, then to fp format. Eventually you should discover the pattern. $\endgroup$ – Emily Feb 6 '15 at 23:17
  • $\begingroup$ So first convert to decimal, then to binary, then normalize, then float-point, and finally hex, right? Finally to hex, because I have to show the result in hex. $\endgroup$ – ahmadhas Feb 6 '15 at 23:24
  • $\begingroup$ Or just Hex to binary. You claim knowledge of how to solve the problem starting from decimal. So, get to where you can start from. $\endgroup$ – Emily Feb 6 '15 at 23:25
  • $\begingroup$ Just wanted to ask another thing, how would I go about converting a negative hex number such as -B32.6 $\endgroup$ – ahmadhas Feb 6 '15 at 23:59
2
$\begingroup$

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).

$\endgroup$
  • 1
    $\begingroup$ Thanks Just wanted to ask u 127+13=10001100 not 10001101, right? $\endgroup$ – ahmadhas Feb 6 '15 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.