Professional Documents
Culture Documents
CS208
Now you've seen unsigned and signed integers. In real life we also need to be able represent numbers with fractional parts (like: 12.5 & 45.39). Called Floating Point numbers. You will learn the IEEE 32-bit floating point representation.
In the decimal system, a decimal point (radix point) separates the whole numbers from the fractional part Examples: 37.25 ( whole = 37, fraction = 25/100) 123.567 10.12345678
Binary Equivalence
The binary equivalent of a floating point number can be determined by computing the binary representation for each part separately.
1) For the whole part: Use subtraction or division method previously learned. 2) For the fractional part: Use the subtraction or method (to be shown next) multiplication
25 24 23 22 21 20 . 2-1 2-2 2-3 2-4 32 16 8 4 2 1 . 1/2 1/4 1/8 1/16 32 16 8 4 2 1 . .5 .25 .125 .0625
x2 0.5 x2 1.0
Step 2: Collect the whole parts in forward order. Put them after the radix point
. .5 . 0
. .5 . 1
.25 - .25 .0
.5 .0
.25 1
.125
.0625
1 0 1. 0
.25 - .25 .0
37 - 32 5 -4 1 -1 0
37.2510 = 100101.012
18.62510 = 10010.1012
Try It Yourself
Convert the following decimal numbers to binary:
60.7510 190.562510
(Answers on next page)
Answers
60.7510 = 111100.112
190.562510 = 10111110.10012
We have no way to store the radix point! Standards committee came up with a way to store floating point numbers (that have a decimal point)
Floating point numbers can be stored into 32bits, by dividing the bits into three parts: the sign, the exponent, and the mantissa.
1 2
10
32
The first (leftmost) field of our floating point representation will STILL be the sign bit:
Solution is Normalization
Every binary number, except the one corresponding to the number zero, can be normalized by choosing the exponent so that the radix point falls to the right of the leftmost 1 bit.
The second field of the floating point number will be the exponent. The exponent is stored as an unsigned 8-bit number, RELATIVE to a bias of 127.
Try It Yourself
How would the following exponents be stored (8-bits, 127-biased): 2-10
28
(Answers on next slide)
Answers
2-10 exponent bias 28 exponent bias -10 +127 117 8-bit value 01110101
8 +127 135
The mantissa is the set of 0s and 1s to the left of the radix point of the normalized (when the digit to the left of the radix point is 1) binary number.
Ex:
1.00101 X 23
(The mantissa is 00101)
The mantissa is stored in a 23 bit field, so we add zeros to the right side and store:
00101000000000000000000
So:
40.1562510 = 101000.001012
101000.00101 = 1.0100000101 x 25
127 + 5 = 132
And convert biased exponent to 8-bit unsigned binary: 13210 = 100001002
24 - 16 8 - 8 0
Result: 11000
Result: .11
-11000.11 = -1.100011 x 24
Try It Yourself
Convert the following numbers to IEEE floating point representation: 60.7510
-190.562510
Answers
60.7510 = 0 10000100 11100110..0 -190.562510 = 1 10000110 011111010010..0
Do the steps in reverse order In reversing the normalization step move the radix point the number of digits equal to the exponent: If exponent is positive, move to the right If exponent is negative, move to the left
01111101
010..0
1 . ____________ x 2 Mantissa
For our number: -1. 01 x 2 2
Exponent ----
-0.01012
Step 4: Convert binary number to the FP equivalent (i.e. Add all column values with 1s in them)
Mantissa 1 . ____________ x 2
----
Exponent
11001.12
Step 4: Convert binary number to the FP equivalent (i.e. Add all column values with 1s in them)
11001.1 = 16 + 8 + 1 +.5
= 25.510
Try It Yourself
Convert the following IEEE floating point numbers to decimal:
0
0
10000010
10000110
1110010..0
01010..0
01111101
10100..0
Answers
0 10000010 1110010..0 = 15.12510 10000110 01010..0 = 168.010 01111101 10100 = -0.4062510