11010192837465114 % 122divmod(14, 12)3-3 % 124(250 + 10) % 2565260 & 0xFF6(11 + 1) % 1200101256010112801640132011601801421
Dial: twelve tiles, 0 to 11; the hand points at the answer mod 12Calculator: the plain running total, before any wrappingBit lamps: a lit lamp is a 1; the lamp off the board is the 256 bit a byte cannot holdPython card: the % operator, divmod() and the & maskA dial with twelve spots, 0 to 11. Adding walks the hand forward one tile at a time and wraps from 11 back to 0; the calculator keeps the plain total, so you can compare 14 with the 2 the hand points at. The byte at the front is the same idea with 256 spots: 250 + 10 = 260 needs a ninth bit, the 256 bit has no room, and 4 is left. Python's own integers never wrap: 250 + 10 is simply 260. Fixed-size integers do: an unsigned 8-bit integer in C (uint8_t) is stored modulo 256.

Clock arithmetic

  1. This dial counts 0 to 11, then starts again. Start at 9 and add 5 hours: 10, 11, 0, 1, 2. You land on 2, not 14. Counting that wraps around like this is called modular arithmetic.

Same remainder

In the machine

Try it in the Python prompt

;; step 1/9 · Clock arithmetic
>>> 9 + 5
14
>>> (9 + 5) % 12
2

A real clock writes 12 where this dial writes 0. In maths the remainders mod 12 are counted from 0, so the spots are 0 to 11. Languages disagree about negative numbers. Python's % takes the sign of the modulus, so -3 % 12 is 9; in C, Java and JavaScript, -3 % 12 is -3.