[Solved]: Why doesn’t the binary fraction representation match the decimal fraction representation?

Problem Detail: The Problem: What value does the hexadecimal number x55544552 represent in data type IEEE floating point? My Work:
    I first wrote out that hexadecimal number in binary and got

0101 0101 0101 0100 0100 0101 0101 0010 

   Now I have my three different sections, the sign, 0, the exponent 10101010 – 127, or 170 – 127, 43, and the fraction portion 101 0100 0100 0101 0101 0010, or 5522770.     Now I can write out my IEEE floating representation as
    1.552270 $*$ 2 $^{43}$
To simplify that expression, I decided to move the decimal point 23 slots to the right(the whole exponent proportion) and got
   (1 101 0100 0100 0101 0101 0010) * 2 $^{20}$) or 13911378 * 2$^{20}$. To me, all my math made sense. When I checked my answer on Hex to IEEE Float, everything matched up but I couldn’t figure out this part on the web application.

The web application has a specified section called fraction which represents the fraction of the floating point representation. In binary, the fraction is 1 .10101000100010101010010 but in decimal, the web application says the fraction is 1.6583655. When I converted 10101000100010101010010 to decimal, I got 5522770. Shouldn’t the fraction decimal representation be 1.5522770 or am I missing something?

Asked By : committedandroider

Answered By : David Richerby

No, that’s not how binary fractions work. A decimal such as $0.13$ represents $$0.13_{mathrm{dec}} = 1times 10^{-1} + 3times10^{-2} = frac{13}{100},.$$ Similarly, a binary fraction such as $0.1101$ represents $$0.1101_{mathrm{bin}} = 1times 2^{-1} + 1times 2^{-2} + 0times 2^{-3} + 1times2^{-4} = frac{13}{16},.$$ $1101_{mathrm{bin}} = 13_{mathrm{dec}}$ but $$0.1101_{mathrm{bin}} = frac{13}{16}neqfrac{13}{100}=0.13_{mathrm{dec}},.$$ Another way to see that you can’t convert fractions into binary by forgetting that they’re fractions is to note that $0.3=0.30$, but $3neq 30$. So it can’t possibly be that you convert $0.3$ in decimal to binary by saying “$3$ in binary is $11$, so $0.3$ in binary is $0.11$”, since $0.3=0.30$ in decimal, so they should be equal in binary, too. But $30$ in binary is $11110$.
Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/41065  Ask a Question  Download Related Notes/Documents