Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Decimal to Floating Point

The Conversion Procedure 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 20 to the end of the binary number (which 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 2k1 1, where k is the
number of bits in the exponent field. For the eight-bit format, k = 3, so the bias is 231 1 = 3. For IEEE 32-bit, k = 8, so the bias is 281 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.

A. The integral part is easy, 210 = 102. For the fractional part:
0.625 2 = 1.25 1 0.25 2 = 0.5 0 0.5 2 = 1.0 1 Generate 1 and continue with the rest. Generate 0 and continue. Generate 1 and nothing remains.

B. So 0.62510 = 0.1012, and 2.62510 = 10.1012. C. Add an exponent part: 10.1012 = 10.1012 20. D. Normalize: 10.1012 20 = 1.01012 21.
E. Mantissa: 0101

F. Exponent: 1 + 3 = 4 = 1002.
G. Sign bit is 0. The result is 01000101. Represented as hex, that is 4516. Convert 0.40625 to our 8-bit floating point format. a. 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.

b. So 0.4062510 = 0.011012. c. Normalize: 0.011012 = 1.1012 2-2. d. Mantissa is 1010, exponent is -2 + 3 = 1 = 0012, sign bit is 0.
So 0.40625 is 00011010 = 1a16 FLOAT TO DECIMAL POINT The Conversion Procedure

The rules for converting a floating point number into decimal are simply to reverse of the decimal to floating point conversion: A. If the original number is in hex, convert it to binary. B. Separate into the sign, exponent, and mantissa fields. C. Extract the mantissa from the mantissa field, and restore the leading one. You may also omit the trailing zeros.

D. Extract the exponent from the exponent field, and subtract the bias to recover the actual exponent of two.
As before, the bias is 2k1 1, where k is the number of bits in the exponent field, giving 3 for the 8-bit format and 127 for the 32-bit.

E. De-normalize the number: move the binary point so the exponent is 0, and the value of the number remains
unchanged. F. Convert the binary value to decimal. This is done just as with binary integers, but the place values right of the binary point are fractions. G. Set the sign of the decimal number according to the sign bit of the original floating point number: make it negative for 1; leave positive for 0. If the binary exponent is very large or small, you can convert the mantissa directly to decimal without denormalizing. Then use a calculator to raise two to the exponent, and perform the multiplication. This will give an approximate answer, but is sufficient in most cases. Convert the 8-bit floating point number e7 (in hex) to decimal.

A. Convert: e716 = 111001112. B. Seprate: 11100111


C. Mantissa: 1.0111

D. Exponent: 1102 = 610; 6 3 = 3. E. De-normalize: 1.01112 23 = 1011.1


F. Convert: Exponents Place Values Bits Value 23 8 1 8 22 4 0 21 2 1 + 2 + 20 2-1 1 0.5 1 . 1 1 + 0.5 = 11.5

G. Sign: negative. Result: e7 is -11.5


Convert the 8-bit floating point number 26 (in hex) to decimal.

a. b. c.
d.

Convert and separate: 2616 = 00100110 2 Exponent: 0102 = 210; 2 3 = -1. Denormalize: 1.0112 2-1 = 0.1011. Convert: Exponents Place Values Bits Value 20 2-1 1 0.5 0 . 1 0.5 2-2 0.25 0 2-3 2-4 0.125 0.0625 1 1 + 0.125 + 0.0625 = 0.6875

e.

Sign: positive Result: 26 is 0.6875.

You might also like