Search code examples
floating-pointfloating-point-conversion

How to convert an IEEE single precision floating point to a decimal value


So I am trying to convert 46bfc000 (which is a floating-point number in IEEE single precision) into a decimal value.

I can get a approximate value, but not the exact value. So here is my work for my approximate value:

1) Convert into binary: 0100 0110 1011 1111 1100 0000 0000 0000

2) Find b-exp: 141-127

3) Convert what is after the decimal value: 2^-1 + 2^-5... = .552726746

4) Now follow this equation format: (1)sign bit * (1. + value in step 3) * 2^b-exp

5) Calculate: +1 X (1.5527226746) X 2^14 = 25439.87501

Now I know that the exact value is: 24544. But I am wondering if there is a way for me to get the exact number, or is it impossible to convert a IEEE single precision binary to a decimal value?


Solution

  • I have figured out the equation to get out the exact number of the binary representation, it is: sign * 2^b-exp * mantissa

    Edit: To get the right mantissa, you need to ONLY calculate it starting at the fractional part of the binary. So for example, if your fractional is 011 1111...

    Then you would do (1*2^-0) + (1*2^-1) + (1*2^-2)...

    Keep doing this for all the numbers and you'll get your mantissa.