The required floating point number can be written as:
s e f
0 10000110 (1)00001100001000000000000
or, the required 32-bit floating point number is:
01000011000001100001000000000000
1.22.3 Multiplication and Division of Floating Point Numbers
Multiplication and division of floating point numbers are rather easy. Here are the steps:
• Add (or subtract) the exponents of the numbers.
• Multiply (or divide) the mantissa of the numbers.
• Correct the exponent.
• Normalize the number.
• The sign of the result is the EXOR of the signs of the two numbers.
Since the exponent is processed twice in the calculations, we have to subtract 127 from the exponent.
An example showing the multiplication of two floating point numbers follows.
Show the decimal numbers 0.510 and 0.7510 in floating point and then calculate their multiplication.
Convert the numbers into floating point as:
0.510 = 1.0000 × 2-1
here, s = 0, e – 127 = -1 or e = 126 and f = 0000
or,
0.510 = 0 01110110 (1)000 0000 0000 0000 0000 0000
Similarly,
0.7510 = 1.1000 × 2-1
here, s = 0, e = 126 and f = 1000
or,
0.7510 = 0 01110110 (1)100 0000 0000 0000 0000 0000
Multiplying the mantissas results in “(1)100 0000 0000 0000 0000 0000.” The sum of the exponents is 126+126=252. Subtracting 127 from the mantissa, we obtain 252–127=125. The EXOR of the signs of the numbers is 0. Thus, the result can be shown in floating point as:
0 01111101 (1)100 0000 0000 0000 0000 0000
This number is equivalent to decimal 0.375 (0.5×0.75=0.375), which is the correct result.
1.22.4 Addition and Subtraction of Floating Point Numbers
The exponents of floating point numbers must be the same before they can be added or subtracted. The steps to add or subtract floating point numbers are:
• Shift the smaller number to the right until the exponents of both numbers are the same. Increment the exponent of the smaller number after each shift.
• Add (or subtract) the mantissa of each number as an integer calculation, without considering the decimal points.
• Normalize the result.
An example follows.
Show decimal numbers 0.510 and 0.7510 in floating point and then calculate the sum of these numbers.
As shown in Example 1.36, we can convert the numbers into floating point as:
0.510 = 0 01110110 (1)000 0000 0000 0000 0000 0000
Similarly,
0.7510 = 0 01110110 (1)100 0000 0000 0000 0000 0000
Since the exponents of both numbers are the same, there is no need to shift the smaller number. If we add the mantissa of the numbers without considering the decimal points, we get:
(1)000 0000 0000 0000 0000 0000
+ (1)100 0000 0000 0000 0000 0000
--------------------------------
(10)100 0000 0000 0000 0000 0000
To normalize the number, shift it right by one digit and then increment its exponent. The resulting number is:
0 01111111 (1)010 0000 0000 0000 0000 0000
This floating point number is equal to decimal number 1.25, which is the sum of decimal numbers 0.5 and 0.75.
A program for converting floating point numbers into decimal, and decimal numbers into floating point, is available for free on the following web site:
http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html
1.23 BCD Numbers
BCD (binary coded decimal) numbers are usually used in display systems such as LCDs and 7-segment displays to show numeric values. In BCD, each digit is a 4-bit number from 0 to 9. As an example, Table 1.4 shows the BCD numbers between 0 and 20.
Table 1.4: BCD numbers between 0 and 20
Decimal | BCD | Binary |
---|---|---|
0 | 0000 | 0000 |
1 | 0001 | 0001 |
2 | 0010 | 0010 |
3 | 0011 | 0011 |
4 | 0100 | 0100 |
5 | 0101 | 0101 |
6 | 0110 | 0110 |
7 | 0111 | 0111 |
8 | 1000 | 1000 |
9 | 1001 | 1001 |
10 | 0001 0000 | 1010 |
11 | 0001 0001 | 1011 |
12 | 0001 0010 | 1100 |
13 | 0001 0011 | 1101 |
14 | 0001 0100 | 1110 |
15 | 0001 0101 | 1111 |
16 | 0001 0110 | 1 0000 |
17 | 0001 0111 | 1 0001 |
18 | 0001 1000 | 1 0010 |
19 | 0001 1001 | 1 0011 |
20 | 0010 0000 | 1 0100 |