The digit sum of a nonnegative integer in a specified radix is the sum of its numerical digits. If
write , with . For example, . In binary representation, the digit sum is the Hamming weight of the digit string.
Since , the positional expansion gives
In decimal representation, this yields the familiar divisibility tests by and : the integer and its digit sum have the same remainder modulo either. For , both and leave remainder modulo . The argument explains the rule from modular arithmetic, rather than relying on a pattern noticed in examples.
The alternating digit sum of a nonnegative integer in radix is
with a positive sign on the units digit. Starting the signs from the opposite end can change the overall sign, so the convention should be stated.
Because , the positional expansion gives . This proves a divisibility test: divides the number exactly when it divides its alternating digit sum. In decimal notation, has alternating sum and equals .
The rule differs from the ordinary digit sum test modulo , which instead uses . Both follow from the same modular arithmetic principle of replacing the radix by its residue before evaluating the digit polynomial.

Articles by others on the same topic (1)

The digit sum, also known as the sum of digits, is calculated by adding together all the individual digits of a given number. For instance, if you take the number 1234, the digit sum would be calculated as follows: 1 + 2 + 3 + 4 = 10 In this case, the digit sum of 1234 is 10. The concept is often used in various areas of mathematics, including number theory and numerical analysis.