Loading...
Floating-point arithmetic combines numbers at a common scale. Align the exponents, operate on signed mantissas with sufficient working space, then normalise and check the final fields.
What you'll be able to do
Use an eight-bit two’s-complement mantissa with the point after the sign bit and a four-bit two’s-complement exponent. A value is mantissa×2^exponent. To add two values, first express both mantissas at the same exponent, usually the larger one. Raising an exponent by one requires dividing its mantissa by two to preserve the value.
For a signed mantissa, an arithmetic right shift repeats the sign bit. A negative operand must remain negative; shifting in zero instead changes its meaning. Retain extra working bits where possible so that alignment does not prematurely discard information. The final storage width and any rounding rule must be stated separately from the working calculation.
Represent 5.5 as 0.1011000×2³ and 3 as 0.1100000×2². Align 3 to exponent 3, giving 0.0110000×2³. Their mathematical mantissa sum is +1.0625, outside the stored signed fractional mantissa’s range. Keep that temporary result with sufficient extra width rather than allowing it to wrap into a negative number.
Divide the sum by two and increase the exponent: 0.1000100×2⁴=8.5. For subtraction, add the negative second value. −3 starts as 1.0100000×2² and aligns to 1.1010000×2³, meaning −0.375×8. Adding to +0.6875×8 gives 0.0101000×2³, then normalises to 0.1010000×2²=2.5.
A non-zero normalised positive mantissa starts 01; a negative one starts 10. Cancellation can require shifting the result left and decreasing the exponent. Exact zero has no first change of sign bit, so it needs separate handling. Verify exponent range before storing a result; four-bit two’s complement permits exponents −8 through +7.
Alignment may lose small contributions when storage is restricted. At exponent 3, the eight-bit mantissa’s least significant weight represents 1/16 in the final value. Adding 0.03125 to 5.5 needs finer precision; if extra bits are discarded under a stated truncation rule, the stored result can remain 5.5. Rounding rules can give a different stored result, so avoid silently assuming one.
| Stage | 5.5 + 3 | 5.5 − 3 |
|---|---|---|
| Common exponent | 3 | 3 |
| First mantissa | 0.1011000 | 0.1011000 |
| Second aligned mantissa | 0.0110000 | 1.1010000 |
| Exact mathematical sum | +1.0625 | +0.3125 |
| Normalised result | 0.1000100 × 2⁴ | 0.1010000 × 2² |
| Denary check | 8.5 | 2.5 |
Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.