Decimal to Floating-Point Conversions

- Convert the absolute value of the number to binary, perhaps with a fractional part after the binary point. This can be done by converting the integral and fractional parts separately. The integral part is converted with the techniques examined previously. The fractional part can be converted by multiplication. This is basically the inverse of the division method: we repeatedly multiply by 2, and harvest each one bit as it appears left of the decimal.
- Append × 20 to the end of the binary number (which does not change its value).
- Normalize the number. Move the binary point so that it is one bit from the left. Adjust the exponent of two so that the value does not change.
- Place the mantissa into the mantissa field of the number. Omit the leading one, and fill with zeros on the right.
- Add the bias to the exponent of two, and place it in the
exponent field. The bias is 2
*k*−1 − 1, where*k*is the number of bits in the exponent field. For the eight-bit format,*k*= 3, so the bias is 23−1 − 1 = 3. For IEEE 32-bit,*k*= 8, so the bias is 28−1 − 1 = 127. - Set the sign bit, 1 for negative, 0 for positive, according to the sign of the original number.

- Convert 2.625 to our 8-bit floating point format.
- The integral part is easy, 2
_{10}= 10_{2}. For the fractional part:0.625 × 2 = 1.25 1 Generate 1 and continue with the rest. 0.25 × 2 = 0.5 0 Generate 0 and continue. 0.5 × 2 = 1.0 1 Generate 1 and nothing remains. _{10}= 0.101_{2}, and 2.625_{10}= 10.101_{2}. - Add an exponent part: 10.101
_{2}= 10.101_{2}× 2^{0}. - Normalize: 10.101
_{2}× 2^{0}= 1.0101_{2}× 2^{1}. - Mantissa: 0101
- Exponent: 1 + 3 = 4 =
100
_{2}. - Sign bit is 0.

_{16}. - The integral part is easy, 2
- Convert -4.75 to our 8-bit floating point format.
- The integral part is 4
_{10}= 100_{2}. The fractional:0.75 × 2 = 1.5 1 Generate 1 and continue with the rest. 0.5 × 2 = 1.0 1 Generate 1 and nothing remains. _{10}= 100.11_{2}. - Normalize: 100.11
_{2}= 1.0011_{2}× 2^{2}. - Mantissa is 0011, exponent is
2 + 3
= 5 = 101
_{2}, sign bit is 1.

_{16} - The integral part is 4
- Convert 0.40625 to our 8-bit floating point format.
- Converting:
0.40625 × 2 = 0.8125 0 Generate 0 and continue. 0.8125 × 2 = 1.625 1 Generate 1 and continue with the rest. 0.625 × 2 = 1.25 1 Generate 1 and continue with the rest. 0.25 × 2 = 0.5 0 Generate 0 and continue. 0.5 × 2 = 1.0 1 Generate 1 and nothing remains. _{10}= 0.01101_{2}. - Normalize: 0.01101
_{2}= 1.101_{2}× 2^{-2}. - Mantissa is 1010, exponent is
-2 + 3
= 1 = 001
_{2}, sign bit is 0.

_{16} - Converting:
- Convert -12.0 to our 8-bit floating point format.
- 12
_{10}= 1100_{2}. - Normalize: 1100.0
_{2}= 1.1_{2}× 2^{3}. - Mantissa is 1000, exponent is
3 + 3
= 6 = 110
_{2}, sign bit is 1.

_{16} - 12
- Convert decimal 1.7 to our 8-bit floating point format.
- The integral part is easy, 1
_{10}= 1_{2}. For the fractional part:0.7 × 2 = 1.4 1 Generate 1 and continue with the rest. 0.4 × 2 = 0.8 0 Generate 0 and continue. 0.8 × 2 = 1.6 1 Generate 1 and continue with the rest. 0.6 × 2 = 1.2 1 Generate 1 and continue with the rest. 0.2 × 2 = 0.4 0 Generate 0 and continue. 0.4 × 2 = 0.8 0 Generate 0 and continue. 0.8 × 2 = 1.6 1 Generate 1 and continue with the rest. 0.6 × 2 = 1.2 1 Generate 1 and continue with the rest. … - Already normalized: 1.1011
_{2}= 1.1011_{2}× 2^{0}. - Mantissa is 1011, exponent is
0 + 3 = 3 =
011
_{2}, sign bit is 0.

_{16}. This is not exact, of course. If you convert it back to decimal, you get 1.6875. - The integral part is easy, 1
- Convert -1313.3125 to IEEE 32-bit floating point format.
- The integral part is 1313
_{10}= 10100100001_{2}. The fractional:0.3125 × 2 = 0.625 0 Generate 0 and continue. 0.625 × 2 = 1.25 1 Generate 1 and continue with the rest. 0.25 × 2 = 0.5 0 Generate 0 and continue. 0.5 × 2 = 1.0 1 Generate 1 and nothing remains. _{10}= 10100100001.0101_{2}. - Normalize: 10100100001.0101
_{2}= 1.01001000010101_{2}× 2^{10}. - Mantissa is 01001000010101000000000, exponent is
10 + 127
= 137 = 10001001
_{2}, sign bit is 1.

_{16} - The integral part is 1313
- Convert 0.1015625 to IEEE 32-bit floating point format.
- Converting:
0.1015625 × 2 = 0.203125 0 Generate 0 and continue. 0.203125 × 2 = 0.40625 0 Generate 0 and continue. 0.40625 × 2 = 0.8125 0 Generate 0 and continue. 0.8125 × 2 = 1.625 1 Generate 1 and continue with the rest. 0.625 × 2 = 1.25 1 Generate 1 and continue with the rest. 0.25 × 2 = 0.5 0 Generate 0 and continue. 0.5 × 2 = 1.0 1 Generate 1 and nothing remains. _{10}= 0.0001101_{2}. - Normalize: 0.0001101
_{2}= 1.101_{2}× 2^{-4}. - Mantissa is 10100000000000000000000, exponent is
-4 + 127
= 123 = 01111011
_{2}, sign bit is 0.

_{16} - Converting:
- Convert 39887.5625 to IEEE 32-bit floating point format.
- The integral part is 39887
_{10}= 1001101111001111_{2}. The fractional:0.5625 × 2 = 1.125 1 Generate 1 and continue with the rest. 0.125 × 2 = 0.25 0 Generate 0 and continue. 0.25 × 2 = 0.5 0 Generate 0 and continue. 0.5 × 2 = 1.0 1 Generate 1 and nothing remains. _{10}= 1001101111001111.1001_{2}. - Normalize: 1001101111001111.1001
_{2}= 1.0011011110011111001_{2}× 2^{15}. - Mantissa is 00110111100111110010000, exponent is
15 + 127
= 142 = 10001110
_{2}, sign bit is 0.

_{16} - The integral part is 39887