In: Computer Science
3.5 (base 10) == 01000000011000000000000000000000 (base 2)
-2.0625 (base 10) == 11000000000001000000000000000000 (base
2)
-7.21875 (base 10) == 11000000111001110000000000000000 (base 2)
Calculate 3.5 * -2.0625 (= -7.21875) using the algorithm for floating point multiplication. You must show work for credit!
In single precison point format with 32 bit representation we can represent a number as
sign fraction/significand/mantissa (23 bits)
| / \
| exponent (8 bits) / \
| / \ / \
0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 1 1 0 1 1
Similarly a given number can be represented with the format
by using these two concepts we can rewrite the numbers as
01000000011000000000000000000000 = 0 10000000 11000000000000000000000
(sign) 128 6291456
So this number could be represented like (-1)0 * 2(128-127) * (1+6291456*2-23) = 1*21*1.75 = 2
11000000000001000000000000000000 = 1 10000000 00001000000000000000000
(sign) 128 262144
So this number could be represented like (-1)1 * 2(128-127) * (1+262144*2-23) = -1*2*1.03125 =2.0625
Their multiplication can do in separate.
That is sign part is multiplied first
So (-1)0 * (-1)1 = (-1)1 = -1 ( this represents the result is a negative number so we can use 1 as the first bit in the answer)
Now we are multiplying the exponential part
21 * 21 = 22 ( So the multiplication result will be 22 )
Now we need to multiply the mantissa part
Finally we will get the result as (-1)1 * 22 * (1+6750208*2-23) = (-1)1 * 4 * 1.8046825 = -7.21875