Logic circuits
When adding two's complement numbers, which condition indicates that an overflow has occurred?
- AWhen the carry into the most significant bit differs from the carry out of the most significant bit
- BWhen the result is 0
- CWhen the sum of the least significant bits is 1
Show answer and explanation
Answer: A. When the carry into the most significant bit differs from the carry out of the most significant bit
In two's-complement addition, overflow occurs when two positives yield a negative or two negatives yield a positive, detected when the carry into the top bit differs from the carry out of it (their XOR is 1). For example, in 4 bits 0111 (7) + 0001 (1) = 1000 (−8). Adding numbers of opposite sign can never overflow. Many CPUs report this in a dedicated flag (the V flag on Arm and others, OF on x86), distinct from the carry flag for unsigned carry-out (C or CF).
- A. Correct. Overflow is when the carries into and out of the MSB differ.
- B. A result of 0 does not indicate overflow.
- C. The least significant bit is irrelevant to overflow detection.