This is going to be another one of my “selfish” posts – written primarily for me to refer back to in the future and not because I believe it will benefit anyone other than me. The idea is one that I always took for granted but had a hard time proving to myself once I decided to try.

Theorem: Suppose we have an M bit unsigned binary integer with value A. Consider the first (least significant) N bits with value B. Then:

Put another way, arithmetic with unsigned binary integers of a fixed length N is always performed modulo .

It is no big secret that exponentiation is just multiplication in disguise. It is a short hand way to write an integer times itself multiple times and is especially space saving the larger the exponent becomes. In the same vein, a serious problem with calculating numbers raised to exponents is that they very quickly become extremely large as the exponent increases in value. The following rule provides a great computational advantage when doing modular exponentiation.

The rule for doing exponentiation in modular arithmetic is:

This states that if we take an integer , raise it to an integer power and calculate the result modulo we will get the same result as if we had taken modulo first, raise it to , and calculate that product modulo .

I must stay focused. I must stay focused. I must stay … I wonder what’s new on Facebook.

I don’t really feel like writing this post mostly because I know that it will be very similar to the other two I have already done: modular addition rule proof and modular subtraction rule proof, but my New Year’s Resolution is to follow things through to completion. Well, that would’ve been my News Years resolution if I had made one. Either way, it’s back to modular arithmetic.

The rule for doing multiplication in modular arithmetic is:

This says that if we multiply integer times integer and take the product modulo , we get the same answer as if we had first taken modulo and multiplied by modulo and taken that product modulo .

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.

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.