MC logo
Decimal to Floating-Point Conversions
[^] Floating-Point Conversion Examples   [^^][^^] Binary/Boolean Main Index
[Decimal to Floating-Point Conversions] [Float to Decimal Conversion]

The Conversion Procedure

The rules for converting a decimal number into floating point are as follows:
  1. 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.
  2. Append × 20 to the end of the binary number (which does not change its value).
  3. 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.
  4. Place the mantissa into the mantissa field of the number. Omit the leading one, and fill with zeros on the right.
  5. Add the bias to the exponent of two, and place it in the exponent field. The bias is 2k−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.
  6. Set the sign bit, 1 for negative, 0 for positive, according to the sign of the original number.

Using The Conversion Procedure