β Understanding Modulus
The modulus operation finds the remainder when one number is divided by another. If A
is the dividend and B
is the divisor, then A mod B = R
, where R
is the remainder.
Example: 8 mod 4 = 0 because 8 divided by 4 is exactly 2 with no remainder.
π Modulo on a Clock
Imagine counting around a circle with numbers 0 to B-1. To find A mod B, start at 0 and step clockwise A times. The number you land on is the result.
Example: 5 mod 3 = 2. Count 5 steps clockwise around a circle marked 0,1,2.
Note: If A is negative, you count counter-clockwise.