By IEEE 754 convention, the floating format consists of one sign bit, 8 bits for the exponent, and 23 bits for the mantissa (with a leading $1$ understood, but not stored).
To multiply two IEEE floats, the sign is the easiest part: The sign of the product is simply the XOR of the factor signs.
Next, let us deal with the mantissas:
- take only the lowest 31 bits and prepend a $1$ (the "hidden bit"), giving a 24 bit (or nicely 3 bytes) string that we interpret as an integer in the range $2^{23},\ldots, 2^{24}-1$
- multiply these to produce a 48 bit (or nicely 6 bytes) integer in the range $2^{46},\ldots,2^{48}-2^{25}+1$. That is, the highest of the 48 bits may be $1$ or $0$ (but then the next highest must be $1$).
- If the highest bit is $0$, we shift our result left by one and remember this fact in order to adjust the exponent later. So now the highest bit is definitely $1$.
- Take only the highest three byte, drop the leading $1$, and here you have the mantissa of the result.
Remains the exponent. By its nature, the exponent of the product is essentially the sum of the factor exponents, but we have to adjust it due to the so-called bias of the exponent (which is a property of the IEEE 754 format) as well as whether or not we had to do the shifting in step 3 of the mantissa computation!
Perhaps it is easiest if we try to find out how to make multiplication by $1$, which is represented as
$$ 1=2^0\cdot(1+0)=0|\underbrace{01111111}_{127}|000\ldots0,$$
work as expected (i.e., the product is simply the other factor).
Note that
$$ 0|\underbrace{01111110}_{126}|111\ldots1$$
is just a tiny bit smaller so should produce nearly the same results under multiplication.
If we multiply
$$ s|\underbrace{eeeeeeee}_E|aaa\ldots a$$
with $1$ as described above, the sign of the result is of course $s$ again.
Next, for the mantissa we first compute
$$10000000\,00000000\,00000000\cdot 1aaaaaaa\,aaaaaaaa\,aaaaaaaa\\
= 01aaaaaa\,aaaaaaaa\,aaaaaaaa\,a0000000\,00000000\,00000000 $$
For the exponent, we remember that we have to shift left before chopping off three bytes and dropping the leading bit.
The final exponent is $E+127-(\text{correction in case of shift required in mantissa})$. As we clearly want $E$, the correction in case of shift required in mantissa must be $127$.
Now what if we compute with the almost-one shown above instead? Sign is clear, but for the mantissa we compute
$$11111111\,11111111\,11111111\cdot 1aaaaaaa\,aaaaaaaa\,aaaaaaaa\\
\approx 2^{24}\cdot 1aaaaaaa\,aaaaaaaa\,aaaaaaaa\\
= 1aaaaaaa\,aaaaaaaa\,aaaaaaaa\,00\ldots$$
so this time there is no shift needed to obtain the original mantissa back (approximately, and I ignore some borderline cases).
The final exponent is $E+126-(\text{correction in case of no shift required})$. To make things work, the correction in case of no shift required in mantissa must be $126$.
In the problem, you multiply
$$ 21.5 = 0|\underbrace{10000011}_{131}|0101100\ldots0$$
and
$$ 12.75 = 0|\underbrace{10000010}_{130}|1001100\ldots0.$$
As
$$ 10101100\,00\ldots \cdot 11001100\,00\ldots = 10001001\, 00010000\,0\ldots,$$
we are in the no-mantissa-shift-needed case, so that the exponent is $131+130-126=135$ and ultimately the IEEE product is
$$0|10000111|0001001000100\ldots $$
We read this as
$$2^{135-127}\cdot\frac{1000 1001 0001_2}{1000 0000 0000_2} =2^8\cdot \frac{2193}{2^{11}}=274.125$$
To be honest that's the biggest point of my problem right now.
I can get the math done without a sweat, but where to place the floating point after the fact is beyond me, haha.
– Erzats Sep 25 '20 at 21:31