← 🔢 Number Systems & Binary Arithmetic
Subtopic 3 of 4

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

  1. Add the bit patterns column by column, passing carries along.
  2. For A − B: invert B, then add 1 (as the carry-in) and add to A.
  3. Signed overflow = carry into the MSB XOR carry out of the MSB.
  4. 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 bit1110
A0101= 5
B0011= 3
Sum1000= -8
Carry out of the MSB (C_out)0
Carry into the MSB (C_in)1
Overflow = C_in ⊕ C_out1 (overflow)
True mathematical result8

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

Remember: Overflow = C_in(MSB) ⊕ C_out(MSB); opposite-sign additions never overflow.
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.