ITPEC FE Morning April 2020 Question 1
For two 8-bit signed integers A and B in 2’s complement format, which of the following will cause an overflow when the addition of A and B is executed?
Explanation
+127 plus +126 — in 2's complement addition, overflow happens only when two operands of the same sign give a sum outside −128 to +127.
An 8-bit signed integer holds −128 to +127. Read each pair and add:
- •(a)
0111 1111+1111 1110: 127 + (−2) = 125 - •(b)
0111 1111+0111 1110: 127 + 126 = 253, above +127; the result bits1111 1101read as −3 - •(c)
1000 0000+0111 0000: −128 + 112 = −16 - •(d)
1111 1111+1111 1111: −1 + (−1) = −2
Only (b) adds two positives and gets a negative sign bit.
Answer (b)
Why not others:
- •(a) — the operands have opposite signs, so the sum lies between them and cannot leave the range; it is 125
- •(c) — again opposite signs; the sum −16 is well inside the range
- •(d) — the addition carries out of bit 7, but a carry out is not a signed overflow; dropping it leaves
1111 1110, which is −2 and correct
Key rule: Signed overflow occurs only when both operands have the same sign bit and the result's sign bit differs; the carry out of the top bit does not signal it.
Basic Theory · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.