LOGBOOK

HELP

Quiz Entry - updated: 2026.07.07

What happens when integer multiplication overflows? Show an example.

The product wraps modulo 2^w; once it exceeds the type's maximum it can flip negative — e.g. repeatedly doubling 1,000,000 eventually goes negative in a 32-bit int.

Step plot of a 32-bit signed int starting at 1000000 and repeatedly doubled; values climb toward the dashed INT_MAX = 2147483647 ceiling then abruptly flip negative at iteration k=12, highlighted in red as the overflow wrap point.

* Repeatedly doubling a 32-bit signed int climbs to just under INT_MAX and then silently wraps to a negative value at iteration 12. *

int i = 1000000;
for (k = 0; k < 20; k++) {
    printf("%2d: %d\n", k, i);
    i = i * 2;
}

Output:

 0:    1000000
 1:    2000000
...
10: 1024000000
11: 2048000000
12: -198967296    <- OVERFLOW! Should be 4096000000
13: -397934592
...

Why this happens:

  • 32-bit signed int max: ~2.1 billion
  • When multiplying exceeds this, bits "wrap around"
  • The sign bit gets set, making the result negative!

Security implication: Integer overflow is a common vulnerability class.

Go deeper:

From Quiz: REVE1 / Overview of Computer Systems | Updated: Jul 07, 2026