CIS3355:
Business Data Structures 
Addendum 2.1: FloatingPoint (Real) Numbers
We already know the basic layout for the data type float (from figure 2.20):
We also know that (generally), the leftmost bit is the sign, and can takeon either ‘0’ or ‘1’ values.
Let's store the value 7.89, OR .789E+1 (i.e., 0.789 * 10^{1}). First, let's talk about how we would store the Exponent vale (+1).
The characteristic of the exponent is not that difficult to understand either. Since we have 7bits, we have a total of 2^{7} = 128 combinations, but since we know that the exponent can be either negative or nonnegative, we really only have ˝ that number.
Not quite. The characteristic of the exponent is stored as a biased exponent. That means that rather than storing the sign and the value separately, we add (bias) a constant term to the true value. In our case, we would add the value 64 (which is ˝ of 128) to the true value. The exponent value –17_{10} (= 10001_{2}, or 0010001_{2} on 7bits) would actually be stored as the value –17 + 64 = 47_{10} (= 101111_{2}, or 0101111_{2} on 7bits); the exponent value 23_{10} (=10111_{2} or 0010111_{2} on 7bits) would actually be stored as the value 23 + 64 = 87_{10} (=1010111_{2}). In our case, the exponent value 1 would actually be stored as 1 + 64 = 65_{10} (= 1000001_{2})
There are some technical reasons, which we need not go into, but of course, it does circumvent the step of having to store the sign and the value separately.
One final quick note on characteristics: the range of exponent values is actually –(2^{6} – 1) through +(2^{6} – 1), or –63 through +63. The binary representation 0000000_{2} (the decimal value 0) is reserved for other uses.
Converting the mantissa to binary requires a somewhat different algorithm than we used to convert integers to binary, but it still has to do with exponent position. For example, the integer 456 would have the exponent positions shown at the left (in other words, 456 = 4*10^{2} + 5*10^{1} + 6*10^{0}). If we were to consider the real number 456.789, however, the exponent positions would appear as the do on the right (in other words, 456.789 = 4*10^{2} + 5*10^{1} + 6*10^{0} + 7*10^{1} + 8*10^{2} + 9*10^{3}). Notice that the exponents for the mantissa are the inverse of the positions for the integer portion of the number.
The procedure we need to use is also the inverse of the procedure we used when converting a decimal integer to binary. Previously, we divided the integer portion by two and kept track of the remainders and collected reverse order received. Now, we need to multiply the mantissa by two and keep track of the quotients and collect in order received. In both cases, however, we can stop when the value to be multiplied or divided is 0.
The mantissa .789, for example could be converted to binary as follows:
And COLLECTING FROM THE TOP, the mantissa .789 would be stored (on 24bits) as: 110010011111101111100111
and the value 7.89 would be stored as: 0 1000001 110010011111101111100111 (on 32bits)
This is true. We previously noted that, unlike integers, not all mantissas can be converted to binary. Sometimes, they become an infinite series.
Much in the same way we checked integers. For example we know that the binary representation of the integer 456_{10} = 111001000_{2} can be checked as: 2^{8} + 2^{7} + 2^{6} + 2^{3} = 256 + 128 + 64 + 8 = 456
Since we know that the positions of the mantissa are the inverse of the integer positions, we know that binary mantissa 110100111111011111001110 (= .789_{10}) can be associated with the positions:
Meaning that the expression could be checked as:
2^{1} + 2^{2} + 2^{5} + 2^{8} + 2^{9} + 2^{10} + 2^{11} + 2^{12} + 2^{13} + 2^{15} + 2^{16} + 2^{17} + 2^{18} + 2^{19} + 2^{22} + 2^{23} + 2^{24 }
First, let’s approach it as a decimal mantissa. The decimal mantissa .789 could be rewritten as:
The binary mantissa (as with integers, ‘0’ bits are ignored) could be rewritten in the same fashion
» .789
We must first normalize the number:
456.789 = 45.6789 * 10^{1} = 4.56789 * 10^{2} = .456789 * 10^{3}
Where the last notation is what we will use to store the number:
Storing the first 8bits (the sign and the characteristic) is relatively easy:
Sign: 0 (positive) Characteristic: 3_{10} + 64_{10} = 67_{10} = 1000011_{2} (on 7bits) Sign and characteristic layout: 01000011 (using the first 8bits)
Converting the mantissa .456789 as we did before
And COLLECTING FROM THE TOP, the mantissa (on 24bits) is: 011101001111000000011111
Therefore, the real number +456.789 would be stored as:
01000011011101001111000000011111 (on 32bits)
Sometimes, but not very often. Naturally, increasing the number of bits we allocate to the mantissa helps increase the precision of the mantissa, but it doesn’t always assure that we will be able to represent values exactly.
Yes.
That is beyond the realm of our discussion. However, there is enough information provided to allow the truly diehard student to figure it out.
They are. As we noted previously, that is why some supercomputers indicate operating speed in terms of flops (floatingpoint operations per second).
