In binary notation, what is the meaning of the digits after the radix point "."?

c, c++, floating-point, ieee-754

Solution

You can convert the part after the decimal point to another base by repeatedly multiplying by the new base (in this case the new base is 2), like this:

0.25 * 2 = 0.5

-> The first binary digit is 0 (take the integral part, i.e. the part before the decimal point).

Continue multiplying with the part after the decimal point:

0.5 * 2 = 1.0

-> The second binary digit is 1 (again, take the integral part).

This is also where we stop because the part after the decimal point is now zero, so there is nothing more to multiply.

Therefore the final binary representation of the fractional part is: 0.012.

Edit:

Might also be worth noting that it's quite often that the binary representation is infinite even when starting with a finite fractional part in base 10. Example: converting 0.210 to binary:

0.2 * 2 = 0.4   ->   0
0.4 * 2 = 0.8   ->   0
0.8 * 2 = 1.6   ->   1
0.6 * 2 = 1.2   ->   1
0.2 * 2 = ...

So we end up with: 0.001100110011...2.

Using this method you see quite easily if the binary representation ends up being infinite.

Problem

I have this example on how to convert from a base 10 number to IEEE 754 float representation ``` Number: 45.25 (base 10) = 101101.01 (base 2) Sign: 0 Normalized form N = 1.0110101 * 2^5 Exponent esp = 5 E = 5 + 127 = 132 (base 10) = 10000100 (base 2) IEEE 754: 0 10000100 01101010000000000000000 ``` This makes sense to me except one passage: ``` 45.25 (base 10) = 101101.01 (base 2) ``` 45 is 101101 in binary and that's okay.. but how did they obtain the 0.25 as .01 ?

Original source