0 · Recall Warm-up
Answer from memory first. Answers are in the Answer Vault at the bottom.
- −23 in 8-bit 2's complement? from Lesson 1.1.1
- Range of 8-bit 2's complement? from Lesson 1.1.1
- How many bits can the sum of two n-bit numbers need? from Lesson 0.1.3
1 · The Hook
🎣
A 2's-complement adder is the same circuit as an unsigned adder: it doesn't even know the numbers are signed. That is the whole point. But when two large positives add up to something above +127 in 8 bits, the result "wraps" to a negative number: overflow. GATE asks you to spot it, both by signs and by carries.
2 · Predict First
🤔
In 8-bit 2's complement, add +100 (0110 0100) and +70 (0100 0110). What bit pattern comes out, and what does it mean?
Make a guess in your head. The answer opens Section 3.
3 · Core Concept
💡
Predict First — the answer
1010 1010, which reads as −86. Two positives gave a negative: the true sum 170 is above +127, so it overflowed.
🗣️
In plain words
To add signed numbers in 2's complement, add the patterns exactly like unsigned numbers and throw away any carry out of the last place. The answer is correct as long as it fits in the range. It doesn't fit (overflow) exactly when two numbers of the same sign give a result of the opposite sign.
1. Addition
Add bit patterns normally; ignore the carry out of the MSB. (−2) + (−3): 1111 1110 + 1111 1101 = (1) 1111 1011 → 1111 1011 = −5 ✓ (the carry out is discarded).
2. Subtraction
A − B = A + (2's complement of B) = A + B' + 1. 5 − 8: 0000 0101 + 1111 1000 = 1111 1101 = −3 ✓. (Hardware: invert B and set the adder's carry-in to 1.)
3. Overflow
The true answer is outside −2ⁿ⁻¹ … 2ⁿ⁻¹ − 1. Two equivalent tests:
- Sign test: both operands have the same sign and the result has the other sign. (Adding a positive and a negative can never overflow.)
- Carry test: carry into the MSB ≠ carry out of the MSB, i.e. overflow V = C_in(MSB) ⊕ C_out. (The symbol ⊕, read "XOR" or "exclusive or", gives 1 when its two bits are different and 0 when they are equal: 0 ⊕ 0 = 0, 0 ⊕ 1 = 1, 1 ⊕ 0 = 1, 1 ⊕ 1 = 0.)
| Sum (8 bits) | Result | Overflow? |
|---|---|---|
| 0110 0100 + 0100 0110 (100 + 70) | 1010 1010 | yes (pos + pos → neg) |
| 1001 1100 + 1011 1010 (−100 + −70) | 0101 0110 | yes (neg + neg → pos) |
| 1000 0001 + 1111 1111 (−127 + −1) | 1000 0000 = −128 | no |
| 0000 0101 + 1111 1000 (5 − 8) | 1111 1101 = −3 | no |
Carry out ≠ overflow for signed numbers: −127 + −1 produces carry out 1 but no overflow.
4. Sign extension
To widen a 2's-complement number, copy the sign bit into the new places. −5 in 4 bits = 1011 → 8 bits 1111 1011 (still −5). Positive numbers get zeros: 0101 → 0000 0101.
5. 1's complement addition (for completeness)
Add normally; if there is a carry out, add it back to the result (end-around carry). This extra step is one reason 1's complement lost.
4 · Visual
Overflow by carries: 100 + 70 in 8 bits
carry INTO each column : 1 0 0 0 1 0 0 0
0 1 1 0 0 1 0 0 (+100)
+ 0 1 0 0 0 1 1 0 (+70)
-----------------
carry OUT of the MSB = 0 1 0 1 0 1 0 1 0 reads as -86
carry into the MSB = 1, carry out of the MSB = 0: 1 XOR 0 = 1 -> OVERFLOW
5 · Worked Examples
Example 1 Easy
In 8-bit 2's complement, compute 5 − 8.
Solution
0000 0101 + 1111 1000 = 1111 1101 = −3, no overflow.
Example 2 Medium
Does (−100) + (−70) overflow in 8 bits? What pattern results?
Solution
1001 1100 + 1011 1010 = 1 0101 0110 → result 0101 0110 (+86): negative + negative → positive, so overflow.
Example 3 GATE
Sign-extend the 4-bit 2's-complement number 1011 to 8 bits. What value does it represent?
Solution
1111 1011 = −5 (same value as 1011).
6 · GATE Traps
⚠️
- Ignore the carry out in 2's-complement addition; it is not the overflow signal.
- Mixed-sign additions never overflow.
- Overflow = carry into MSB XOR carry out of MSB.
- Sign extension copies the sign bit; padding a negative number with 0s changes its value.
7 · Memory Hook
🧠
"Add, drop the carry. Same signs in, other sign out = overflow. Extend by copying the sign."
8 · Connect the Dots
Addition and subtraction are done. The next lesson covers the other arithmetic moves: shifts (logical vs arithmetic) and signed multiplication with Booth's algorithm, a GATE favourite for counting additions and subtractions.
9 · Self-Test
GATE format. Try every question before opening the vault.
Q1MCQ1 markOverflow
Which 8-bit 2's-complement addition overflows?
- (A) 0110 0100 + 0100 0110
- (B) 1111 1110 + 1111 1101
- (C) 1000 0001 + 1111 1111
- (D) 0000 0101 + 1111 1000
Q2NAT1 markSubtraction
In 8-bit 2's complement, 0000 0101 − 0000 1000 gives a pattern. What value does it represent?
Numerical answer: ________
Q3NAT2 marksOverflow by carries
In the 8-bit addition 1001 1100 + 1011 1010, what is the value (in decimal) of the 8-bit result read as 2's complement?
Numerical answer: ________
Q4MCQ1 markOverflow test
Overflow in 2's-complement addition occurs exactly when:
- (A) there is a carry out of the MSB
- (B) the result is negative
- (C) the carry into the MSB differs from the carry out of the MSB
- (D) both operands are negative
Q5NAT1 markSign extension
The 4-bit 2's-complement number 1011 is sign-extended to 8 bits. What is the 8-bit pattern read as an unsigned number?
Numerical answer: ________
10 · Rule Card
- 2's-complement add: add the patterns, discard the carry out.
- A − B = A + B' + 1.
- Overflow: same-sign operands give an opposite-sign result; equivalently carry into MSB ⊕ carry out of MSB = 1. Mixed signs never overflow.
- Sign extension: copy the MSB. 1's complement addition needs an end-around carry.
11 · Concept Ledger
Unlocked in this lesson. From here on, these terms may be used.
2's-complement additiondiscarding the carry outsubtraction by adding the complementsigned overflowsign test for overflowcarry test for overflowsign extensionend-around carry
12 · Answer Vault
Answer Vault
Try the questions first. Open when you are ready to check.
Recall Warm-up
- 1110 1001.
- −128 … +127.
- n + 1.
Self-Test
Q1 Answer: (A)1 mark
100 + 70 = 170 > 127.
- (B) is wrong: −5 fits.
- (C) is wrong: −128 fits.
- (D) is wrong: Mixed signs never overflow.
Re-read: Lesson 1.1.2 — 2's-complement arithmetic: addition, subtraction, overflow, sign extension
Q2 Answer: -31 mark
5 − 8.
Re-read: Lesson 1.1.2 — 2's-complement arithmetic: addition, subtraction, overflow, sign extension
Q3 Answer: 862 marks
0101 0110: negative + negative gave a positive (overflow).
Re-read: Lesson 1.1.2 — 2's-complement arithmetic: addition, subtraction, overflow, sign extension
Q4 Answer: (C)1 mark
V = C_in ⊕ C_out at the MSB.
- (A) is wrong: −127 + −1 has a carry out but no overflow.
- (B) is wrong: Many correct results are negative.
- (D) is wrong: Not sufficient.
Re-read: Lesson 1.1.2 — 2's-complement arithmetic: addition, subtraction, overflow, sign extension
Q5 Answer: 2511 mark
1111 1011.
Re-read: Lesson 1.1.2 — 2's-complement arithmetic: addition, subtraction, overflow, sign extension