Quiz Entry - updated: 2026.07.07
How does unsigned addition handle overflow?
It wraps: the result is (x + y) mod 2^w — any carry beyond bit w−1 is simply dropped.
* Unsigned values live on a clock of 0..2^w−1: adding 12 + 7 runs off the top and wraps around to 19 mod 16 = 3. *
If sum ≥ 2^w, the result wraps: result = (x + y) mod 2^w
Example (4-bit, max=15):
12 + 7 = 19, but 19 mod 16 = 3
Binary: 1100 + 0111 = 10011 → keeps only 0011
Detecting overflow: If result < either operand, overflow occurred.
// Check for unsigned overflow
unsigned sum = x + y;
if (sum < x) { /* overflow! */ }
Go deeper:
Integer overflow (Wikipedia) — wraparound, its security consequences, and why unsigned is modular.