Computer Arithmetic
How is overflow detected when adding two unsigned integers?
- ACheck whether the result's most significant bit became 1
- BCheck whether the two inputs' most significant bits are equal
- CCheck whether a carry came out of the most significant bit
Show answer and explanation
Answer: C. Check whether a carry came out of the most significant bit
In unsigned addition, a carry out of the most significant bit means the result exceeded the largest value the bit width can hold. CPUs record this carry in a carry flag, so checking it detects overflow. A result whose top bit is 1 is merely a large number, not an overflow. Comparing the carry into and out of the top bit is the method for detecting signed overflow.
- A. A top bit of 1 can simply be a large in-range number.
- B. Comparing the inputs' top bits alone cannot detect it.
- C. Correct. The carry out of the top bit (the carry flag) indicates it.