Best afterDecimal to binary·Modular arithmetic: wrapping around

Overflow

A real computer stores a number in a fixed number of bits. Count past the largest value those bits can hold and there is nowhere for the carry to go — so it wraps around to zero. Python hides this from you, which is exactly why it catches people out. (This is not the same as roundoff — keep the two straight.)

Count upward in a fixed 8-bit register (it can only hold 0 to 255) and see what happens past the top.

Overflow — when the counter runs out of room execution-derived · CPython
variables
state after line 1 runs
variablevalue
count254

notecount starts at 254. Pretend count lives in a fixed 8-bit register — it can only hold whole numbers from 0 to 255.

step 1 / 10

Click a line, drag the slider, or use the keys.

What you are looking at

An 8-bit register holds whole numbers from 0 to 255 — that is all 8 bits can encode. We start at 254 and tick upward.

Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.