“Casting out nines” and “casting out elevens”

Appendix to “Checksum calculators

When “casting out nines”, one adds the digits of a number, and, if this sum exceeds 9, the digits of the sum, etcetera (a final 9 becomes 0).

When “casting out elevens”, one alternately adds and subtracts the digits of a number, and, if this sum exceeds 9, the digits of the sum, etcetera. If the final sum is negative, 11 is added.

If A = Σi=0 ai 10i

where 0≤ai<10,

and the result of casting out nines is called A9 then

A9 = Σi=0 ai mod 9.

Since 10i mod 9 = 1,

A9 = A mod 9.

Similarly, if the result of casting out elevens is called A11 then

A11 = Σi=0 (−1)i ai mod 11.

If, for convenience, we write 10 mod 11 = −1 (instead of 10), then 10i mod 11 = (−1)i and

A11 = A mod 11.

In general,

(A + B) mod n = ((A mod n) + (B mod n)) mod n,

(A − B) mod n = ((A mod n) − (B mod n))mod n

and

(A × B) mod n = (A mod n) × (B mod n)) mod n.

Any n would do, but since modulo 9 and modulo 11 are so easily calculated, n=9 and n=11 are commonly used.

If you are used to hexadecimal numbers, “casting out 15s” and “casting out 17s” would be more convenient.

For numbers used in an addition, subtraction or multiplication the sum, difference or product of their checksums should equal the checksum of the sum, difference or product. For division the product of the check digits of divisor and (integer part of) quotient should equal the difference between the check digits of dividend and remainder.