Computer Arithmetic

How is overflow detected when adding two unsigned integers?

  1. ACheck whether the result's most significant bit became 1
  2. BCheck whether the two inputs' most significant bits are equal
  3. 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.
Practice this topic Back to topic

More Computer Arithmetic questions

  1. Which correctly describes the spacing between adjacent representable floating-point values?
  2. Up to what value can IEEE 754 single precision represent every integer exactly, starting from 0?
  3. Why are monetary amounts often handled as integers in the smallest unit (one yen or one cent) rather than as binary floating point?
  4. In mixed-precision AI training, why are master weights kept in FP32 while most computation is done in FP16 or bfloat16?
  5. In unsigned fixed point with the low 4 of 8 bits as the fraction, what value does the bit pattern 0011 1000 represent?