Abraham Lincoln once famously said, “Everybody loves a compliment.” I suspect that if he had been a mathematician he would have loved complements, too. We’ve already seen what complements are and talked about the two most prolific: the radix complement and the diminished radix complement. Now it’s time to explore how we can leverage complements to do some really interesting integer arithmetic. Using complements we can subtract one positive integer from another or add a negative integer to a positive one by simply performing addition with two positive integers. The algorithm behind this black magic is called the **Method of Complements**.

I’ve already presented and proved the rule for modular addition, so for a sense of completeness, but mostly to satisfy my OCD, now I’ll cover the rule for modular subtraction. When doing subtraction in modular arithmetic, the rule is:

If we subtract integer from integer and calculate the difference modulo , we get the same answer as if we had subtracted modulo from modulo and then calculated that difference modulo . Like the modular addition rule, this rule can also be expanded to include multiple integers. Continue reading »

Addition in modular arithmetic is much simpler than it would first appear thanks to the following rule:

This says that if we are adding two integers and and then calculating their sum modulo , the answer is the same as if we added modulo to modulo and then calculated that sum modulo . Note that this equation can be extended to include more than just two terms. Continue reading »