Modular Arithmetic
Teens & adults Computing Number theory
Mod gives the remainder after division. 17 mod 5 = 2 (17 = 5·3 + 2). It's "clock math": 14:00 and 2:00 are the same hour on a 12-hour dial because 14 mod 12 = 2.
Reading remainders
17 mod 5 = 2 (17 = 5×3 + 2)
24 mod 6 = 0 (divides exactly — no remainder)
7 mod 10 = 7 (smaller than the modulus, unchanged)
The two everyday uses
- Even/odd: n mod 2 = 0 → even. The fastest parity test that exists.
- Wrap-around: index mod length cycles an array. Frame counters, circular buffers, day-of-week math — all mod.
position 57 in a 32-slot ring buffer:
57 mod 32 = slot 25
hour 23 + 5 more hours:
(23 + 5) mod 24 = 4 AM
In ALB
MOD is a reserved keyword — i MOD 64
wraps indexes, frame MOD 2 = 0 detects even frames
for blink effects. Modular thinking shows up in hashing,
checksums, and every tile-map you'll ever scroll.
Practice
23 mod 5 = ___
48 mod 8 = ___
100 mod 13 = ___
n mod 2 = 0 means n is:
Next: math home · Back: floating point