Decimal to binary conversion of floating point numbers.

To convert a number like 11.7510 to binary we do the following. Consider the number before the decimal point. To convert this we continually divide by 2 and the remainder gives binary digits reading up the way.

2| 11   1   ^
2| 5   1   |
2| 2   0   |
2| 1   1   |
0    
So 1110 is 1011 in binary. For the fraction part we continually multiply it by 2 until we get zero left over or we see a recurring pattern. If the product is greater than 1 then we subtract the 1 and multiply what's left over by 2.

Consider 0.75 for instance.

0.75 x 2 = 1.5
0.50 x 2 = 1.0
0.00 x 2 = 0.0

We then read the digits downwards so 0.7510 = 0.1102. This should be obvious as 0.75 is 3/4 which is equal to 1/2 + 1/4.

Binary to decimal conversion of floating point numbers.

Consider a number like the one below:

1 1 0 1 . 1 0 0 1 12
23 22 21 20 . 2-1 2-2 2-3 2-4 2-5
8 4 2 1 . 1/2 1/4 1/8 1/16 1/3210
From this we can see that 1101.100112 is equal to 8 + 4 + 1 + 1/2 + 1/16 + 1/3210. Which is 13.564453125.

IEEE 754 Standard

This uses 32 bits (binary digits) fo single precision numbers. So that is 32 1s and 0s.

Recall that a number like 1,235,000 can be written in scientific notation as 1.235 x 106. Similiarly 13.564453125 can be written as 1.3564453125 x 101 or in binary as 1.10110011 x 2 3

We can represent numbers on a computer in a similiar fashion. For IEEE 754 format 1 bit is kept for the sign, 8 bits for the exponent and the remaining 23 for the fraction.

+/- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Sign E x p o n e n t _ _ _ _ _ _ _ _ F r a c t i o n _ _ _ _ _ _ _

Always writing the number as 1.XXX x 10Y is called normalised format. If we always write numbers in this format then there is always a one before the decimal point so we can assume that the one is there. Thus we don't need to store it, which frees up one bit.This allows us to store a bigger number.

In the IEEE 754 standard excess 127 is used to express the exponent. So the exponent ranges from -126 to 127. However because we are using the excess notation this is actual stored as 1 to 254 (i.e. -126+127 and 127+127). You might think that this should be -127 to 128 and therefore 0 to 255. However 0 and 255 are used for denormalised numbers, which basically are used to represent numbers which underflow. (For more details see handout P.572)

Example

Show how 0.510 is represented in the IEEE 754 Standard.

Firstly we need to convert this to a binary number. We can use the method describe above or by inspection we can figure out that this is 0.12. This should be obvious as 0.5 is a half or 1/2. 0.12 in normalised format is 1.000 x 2 -1. From this it is clear that the fractional part is zero. Thus we will have 23 O's in the purple section of the above table. The exponent is -1. However in the IEEE 754 standard this is 126 ( -1 + 127). 12610 is 111 11102, using 8 bits this is 0111 11102. The number is positive so the sign bit is 0, (if the number was negative the sign bit would be 1). Filling these three values into the table for the sign, exponent and fraction results in

Sign E x p o n e n t _ _ _ _ _ _ _ _ F r a c t i o n _ _ _ _ _ _ _
0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 F 0 0 0 0 0 0

where 3F000000 is the value in HEX.

Hosted by www.Geocities.ws

1