The rules for converting a decimal number into floating point are as follows:
A. 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
B. Append × 2 to the end of the binary number (which B. does not change its value)
C. 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
D. Place the mantissa into the mantissa field of the number. Omit the leading one, and fill with zeros on the right.
E. Add the bias to the exponent of two, and place it in the exponent field. The bias is 2 power 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 2 power(3-1) − 1 = 3. For IEEE 32-bit, k = 8, so the bias is 2 power(8-1) − 1 = 127.
F. 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, 210 = 102. 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.
A. 0.62510 = 0.1012, and 2.62510 = 10.1012.
B. Add an exponent part: 10.1012 = 10.1012 × 20.
C. Normalize: 10.1012 × 20 = 1.01012 × 21.
D. Mantissa: 0101
E. Exponent: 1 + 3 = 4 = 1002.
F. Sign bit is 0.
The result is 0 100 0101 . Represented as hex, that is 4516.
—————– Thanks everyone