Computer Arithmetic

In C, what is the result of subtracting 1 from 0 in a 32-bit unsigned integer (unsigned int)?

  1. A−1
  2. B4294967295
  3. CIt stays at 0
Show answer and explanation

Answer: B. 4294967295

Unsigned integers have no negatives, and C defines their results modulo 2³² (wrapping around). 0 − 1 becomes 2³² − 1 = 4294967295, all ones in binary. That is why a loop that counts an unsigned variable down with the condition i >= 0 never ends: the condition is always true. Unsigned types cannot represent −1, and they do not saturate at 0.

  • A. Unsigned integers cannot represent negative numbers.
  • B. Correct. It wraps around to 2³² − 1 = 4294967295.
  • C. It does not saturate at 0.
Practice this topic Back to topic

More Computer Arithmetic questions

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