1.3Binary addition, subtraction and overflow
The idea
Adding in 2's complement is the same as adding unsigned numbers, and subtraction is addition of the negated number. The only question is whether the answer fits: that is overflow.
Think of it like this: A car odometer with 4 digits: 9999 + 1 wraps to 0000, so the answer is wrong unless you notice the carry.
Why it exists
Overflow detection and "do this addition" questions are the main arithmetic marks in this topic.
How it works
- Add the bit patterns column by column, passing carries along.
- For A − B: invert B, then add 1 (as the carry-in) and add to A.
- Signed overflow = carry into the MSB XOR carry out of the MSB.
- Same-sign operands with an opposite-sign result also mean overflow; unsigned overflow is just the carry out.
Worked example: 0110 + 0101 in 4 bits
6 + 5 = 11, but 0110 + 0101 = 1011, which reads as −5. Carry into the MSB is 1 and carry out is 0, so they differ: overflow.
Now play with it
- →Press 7 + 1 and then −8 + −1 to see the two overflow directions.
- →Press 5 − 3 and watch B turn into its 2's complement.
| carry into bit | 1 | 1 | 1 | 0 | |
|---|---|---|---|---|---|
| A | 0 | 1 | 0 | 1 | = 5 |
| B | 0 | 0 | 1 | 1 | = 3 |
| Sum | 1 | 0 | 0 | 0 | = -8 |
Signed overflow happens exactly when the carries into and out of the MSB differ. Equivalent test: two operands of the same sign give a result of the opposite sign. Unsigned arithmetic instead uses the carry out of the MSB as the error flag.
Check yourself
In 4-bit 2's complement, 0110 + 0101 gives
Exam notes (the dense version)
A − B is computed as A + (2's complement of B) with carry-in 1 added to the inverted B. Signed (2's complement) overflow happens iff the carry into the MSB differs from the carry out of the MSB, or equivalently when two operands of the same sign give a result of the opposite sign. Adding operands of opposite signs can never overflow. For unsigned numbers the carry out of the MSB signals the error (for subtraction, the absence of a carry means a borrow). In 1's complement the end-around carry is added back.
Previous year questions: Number Systems & Binary Arithmetic (5)
PYQs are grouped by topic, so this is the full set for Number Systems & Binary Arithmetic; try the ones that match this subtopic. Open all 5 on the topic page.