mathfloating-pointbinaryieee-754calculation

Converting a number to IEEE 754


“Convert the decimal number 10/32 to the 32-bit IEEE 754 floating point and express your answer in hexadecimal.”

I understand how to convert a decimal number to IEE 754. But I am confused on how to answer this—it only gives me a quotient? I am not allowed to use a calculator, so I am unsure how to work this out. Should I convert them both to binary first and divide them?


Solution

  • I see it like this:

    10/32 =        // input
    10/2^5 =       // convert division by power of 2 to bitshift
    1010b >> 5 =
    .01010b        // fractional result
    --^-------------------------------------------------------------
      |
    first nonzero bit is the exponent position and start of mantissa
    ----------------------------------------------------------------
    man = (1)010b           // first one is implicit
    exp = -2 + 127 = 125    // position from decimal point + bias
    sign = 0                // non negative
    ----------------------------------------------------------------
    0 01111101 01000000000000000000000 b
    ^    ^                ^
    |    |            mantissa + zero padding
    |   exp
    sign
    ----------------------------------------------------------------
    0011 1110 1010 0000 0000 0000 0000 0000 b
       3    E    A    0    0    0    0    0 h
    ----------------------------------------------------------------
    3EA00000h
    

    Yes the answer of Eric Postpischil is the same approach (+1 btw) but I didn't like the formating as it was not clear from a first look what to do without proper reading the text.