Loading...
Binary arithmetic follows place-value rules, but a fixed register can retain only a limited number of bits. Check the mathematical result before deciding whether a bit pattern has overflowed.
What you'll be able to do
An unsigned n-bit integer represents values from zero to 2ⁿ-1. Column addition uses the same place-value principle as decimal: 1+1 gives binary 10, writing zero and carrying one into the next column. Include any carry arriving from the previous column.
A result needing more than n bits cannot fit the stated unsigned width. If only the low n bits are retained, the stored pattern is the mathematical result modulo 2ⁿ. That retained value should not be reported as the correct unrestricted sum.
Binary multiplication forms a partial product for each multiplier bit. A zero contributes no set partial product; a one contributes the multiplicand shifted to the appropriate place. Add the partial products, allowing enough result width.
For 1101₂×11₂, the partial products are 1101 and 11010, giving 100111₂. The decimal check is 13×3=39. Multiplying two n-bit values can require up to 2n result bits, so a width adequate for each input may not be adequate for the product.
A logical left shift inserts zeroes on the right; a logical right shift inserts zeroes on the left. For unsigned values, a left shift by one corresponds to doubling if no significant bit is lost. A right shift by one gives integer division by two with the discarded low bit removed.
Shifts change a stored pattern rather than guaranteeing an exact arithmetic result for every interpretation. A left shift can overflow a fixed width, and a logical right shift is not the same as preserving the sign of a negative two’s-complement number. State the width and representation before reasoning from the pattern.
| 8-bit unsigned operation | Mathematical value | Retained low 8 bits |
|---|---|---|
| 200+100 | 300 | 00101100 = 44 |
| 00110110 left shift 1 | 108 | 01101100 |
| 00110111 right shift 1 | 27 after discarding remainder | 00011011 |
Eight-bit 11111111+00000001 produces a mathematical unsigned result 256, beyond 255, with retained pattern 00000000. Under a signed interpretation, the same operands represent −1 and +1, whose exact result zero fits. The interpretation changes the range test even though the bit-column addition is identical.
Use the declared width and signedness throughout a trace. For subtraction, distinguish a mathematically negative unsigned result from a valid signed result, and state whether the task wants an exact answer, a wider representation or the retained modular pattern.
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.