Wednesday, May 10, 2017

Represent floating point in IEEE754

Converting Normalized from Base 10 to IEEE 754

Let's convert 10.25 from base 10 to IEEE 754 single precision. Here's the steps:

  • Convert the number left of the radix point to base 2Thus, 1010 is 10102.
  • Convert the number right of the radix point to base 2.Thus, .2510 is .012.
  • Add the two.This results in 1010 + 0.01, which is 1010.01.
  • Write this in binary scientific notation.This is 1010.01 X 20, which is 1.01001 X 23.
  • Write this in IEEE 754 single precision.This is 1010.01 X 20, which is 1.01001 X 23.
  • Convert 3 to the correct bias. Since the bias is 127, add 127 to 3 to get 130 and convert to binary. This turns out to be 1000 0010.
  • Write out the number in the correct representation
    S    Exp            Fraction
    - --------- ----------------------------
    0 1000 0010 0100 1000 0000 0000 0000 000
    
    Notice that the hidden "1" is not represented in the fraction.
    https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/float.html