001100
or 1100
In this example 4 bits are needed to show the final result.
Multiply binary numbers 1001 and 1010.
Multiplying the numbers:
1001
1010
----
0000
1001
0000
1001
-------
1011010
In this example 7 bits are required to show the final result.
1.20 Division of Binary Numbers
Division with binary numbers is similar to division with decimal numbers. An example follows.
Divide binary number 1110 into binary number 10.
Dividing the numbers:
111
10|―――
1110
10
----
11
10
----
10
10
----
00
gives the result 1112.
1.21 Floating Point Numbers
Floating point numbers are used to represent noninteger fractional numbers, for example, 3.256, 2.1, 0.0036, and so forth. Floating point numbers are used in most engineering and technical calculations. The most common floating point standard is the IEEE standard, according to which floating point numbers are represented with 32 bits (single precision) or 64 bits (double precision).
In this section we are looking at the format of 32-bit floating point numbers only and seeing how mathematical operations can be performed with such numbers.
According to the IEEE standard, 32-bit floating point numbers are represented as:
31 30 23 22 0
X XXXXXXXX XXXXXXXXXXXXXXXXXXXXXXX
↑ ↑ ↑
sign exponent mantissa
The most significant bit indicates the sign of the number, where 0 indicates the number is positive, and 1 indicates it is negative.
The 8-bit exponent shows the power of the number. To make the calculations easy, the sign of the exponent is not shown; instead, the excess-128 numbering system is used. Thus, to find the real exponent we have to subtract 127 from the given exponent. For example, if the mantissa is “10000000,” the real value of the mantissa is 128 – 127 = 1.
The mantissa is 23 bits wide and represents the increasing negative powers of 2. For example, if we assume that the mantissa is “1110000000000000000000,” the value of this mantissa is calculated as 2–1 + 2-2 + 2-3 = 7/8.
The decimal equivalent of a floating point number can be calculated using the formula:
Number = (–1)s 2e-127 1.f
where
s = 0 for positive numbers, 1 for negative numbers
e = exponent (between 0 and 255)
f = mantissa
As shown in this formula, there is a hidden 1 in front of the mantissa (i.e, the mantissa is shown as 1.f ).
The largest number in 32-bit floating point format is:
0 11111110 11111111111111111111111
This number is (2–2–23)2127 or decimal 3.403×1038. The numbers keep their precision up to 6 digits after the decimal point.
The smallest number in 32-bit floating point format is:
0 00000001 00000000000000000000000
This number is 2–126 or decimal 1.175×10–38.
1.22 Converting a Floating Point Number into Decimal
To convert a given floating point number into decimal, we have to find the mantissa and the exponent of the number and then convert into decimal as just shown. Some examples are given here.
Find the decimal equivalent of the floating point number: 0 10000001 10000000000000000000000
Here
sign = positive
exponent = 129 – 127 = 2
mantissa = 2-1 = 0.5
The decimal equivalent of this number is +1.5 × 22 = +6.0.
Find the decimal equivalent of the floating point number: 0 10000010 11000000000000000000
In this example,
sign = positive
exponent = 130 – 127 = 3
mantissa = 2-1 + 2-2 = 0.75
The decimal equivalent of the number is +1.75 × 23 = 14.0.
1.22.1 Normalizing Floating Point Numbers
Floating point numbers are usually shown in normalized form. A normalized number has only one digit before the decimal point (a hidden number 1 is assumed before the decimal point).
To normalize a given floating point number, we have to move the decimal point repeatedly one digit to the left and increase the exponent after each move.
Some examples follow.
Normalize the floating point number 123.56
If we write the number with a single digit before the decimal point we get:
1.2356 × 10²
Normalize the binary number 1011.12
If we write the number with a single digit before the decimal point we get:
1.0111 × 2³
1.22.2 Converting a Decimal Number into Floating Point
To convert a given decimal number into floating point, carry out the following steps:
• Write the number in binary.
• Normalize the number.
• Find the mantissa and the exponent.
• Write the number as a floating point number.
Some examples follow:
Convert decimal number 2.2510 into floating point.
Write the number in binary:
2.2510 = 10.012
Normalize the number:
10.012 = 1.0012 × 21
Here, s = 0, e – 127 = 1 or e = 128, and f = 00100000000000000000000.
(Remember that a number 1 is assumed on the left side, even though it is not shown in the calculation). The required floating point number can be written as:
s e f
0 10000000 (1)001 0000 0000 0000 0000 0000
or, the required 32-bit floating point number is:
01000000000100000000000000000000
Convert the decimal number 134.062510 into floating point.
Write the number in binary:
134.062510 = 10000110.0001
Normalize the number:
10000110.0001 = 1.00001100001 × 27
Here, s = 0, e – 127 = 7 or e = 134, and f = 00001100001000000000000.