Base Conversion and Modular Arithmetic

You know how we count in base 10? That’s just a convention. We could count in any base. Computers use base 2 (binary). Programmers use base 16 (hexadecimal). Mathematicians use whatever base makes the problem easier.

And then there’s modular arithmetic—basically clock math. It shows up everywhere in competitions and makes huge problems manageable.

Let’s talk about both.

Base Conversion: Same Number, Different Representation

The Idea

In base 10, each digit represents a power of 10. The number 123 means 1×102+2×101+3×1001 \times 10^2 + 2 \times 10^1 + 3 \times 10^0.

In base 2 (binary), each digit represents a power of 2. The number 1011012101101_2 means 1×25+0×24+1×23+1×22+0×21+1×20=451 \times 2^5 + 0 \times 2^4 + 1 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 = 45.

Same number, different way of writing it.

Converting to Binary (The Easy Way)

Want to convert 45 to binary? Keep dividing by 2 and write down the remainders:

  • 45÷2=2245 \div 2 = 22 remainder 11
  • 22÷2=1122 \div 2 = 11 remainder 00
  • 11÷2=511 \div 2 = 5 remainder 11
  • 5÷2=25 \div 2 = 2 remainder 11
  • 2÷2=12 \div 2 = 1 remainder 00
  • 1÷2=01 \div 2 = 0 remainder 11

Now read the remainders from bottom to top: 1011012101101_2. That’s it.

Check: 1×32+0×16+1×8+1×4+0×2+1×1=451 \times 32 + 0 \times 16 + 1 \times 8 + 1 \times 4 + 0 \times 2 + 1 \times 1 = 45. ✓

Other Bases

Same trick works for any base. Converting 314 to base 5?

  • 314÷5=62314 \div 5 = 62 remainder 44
  • 62÷5=1262 \div 5 = 12 remainder 22
  • 12÷5=212 \div 5 = 2 remainder 22
  • 2÷5=02 \div 5 = 0 remainder 22

So 31410=22245314_{10} = 2224_5.

Hexadecimal (Base 16)

This one’s fun because we need 16 digits. We use 0-9, then A-F for 10-15.

Converting 255 to hex:

  • 255÷16=15255 \div 16 = 15 remainder 1515 (that’s F)
  • 15÷16=015 \div 16 = 0 remainder 1515 (that’s F again)

So 25510=FF16255_{10} = FF_{16}. Neat, right?

Converting Back to Base 10

This is easier. Just multiply each digit by its place value and add.

1011012=1×32+0×16+1×8+1×4+0×2+1×1=45101101_2 = 1 \times 32 + 0 \times 16 + 1 \times 8 + 1 \times 4 + 0 \times 2 + 1 \times 1 = 45.

3A7163A7_{16}? A is 10, so: 3×256+10×16+7×1=768+160+7=9353 \times 256 + 10 \times 16 + 7 \times 1 = 768 + 160 + 7 = 935.

The Shortcut for Powers of 2

Converting between binary and octal (base 8) or hex (base 16) is super easy because 8 and 16 are powers of 2.

For binary to octal: group digits in threes from right to left. 1011012101101_2 becomes 101101 101101, which is 585_8 585_8, so 55855_8.

For binary to hex: group digits in fours. 1011012101101_2 becomes 00100010 11011101 (pad with zeros), which is 2162_{16} D16D_{16}, so 2D162D_{16}.

Modular Arithmetic: Clock Math

The Basic Idea

Modular arithmetic is about remainders. When you work “modulo nn,” you only care about what’s left after dividing by nn.

17≡2(mod5)17 \equiv 2 \pmod{5} because both 17 and 2 leave remainder 2 when divided by 5. Or equivalently, because 17−2=1517 - 2 = 15 is divisible by 5.

It’s like a clock. On a 12-hour clock, 13 o’clock is 1 o’clock. That’s 13≡1(mod12)13 \equiv 1 \pmod{12}.

Why It’s Useful

It makes huge problems small. Want the last digit of 720257^{2025}? Work modulo 10.

Find the pattern:

  • 71≡7(mod10)7^1 \equiv 7 \pmod{10}
  • 72=49≡9(mod10)7^2 = 49 \equiv 9 \pmod{10}
  • 73=343≡3(mod10)7^3 = 343 \equiv 3 \pmod{10}
  • 74=2401≡1(mod10)7^4 = 2401 \equiv 1 \pmod{10}
  • 75=74⋅7≡1⋅7≡7(mod10)7^5 = 7^4 \cdot 7 \equiv 1 \cdot 7 \equiv 7 \pmod{10}

It repeats every 4. Since 2025=4×506+12025 = 4 \times 506 + 1, we have: 72025=74×506+1=(74)506⋅71≡1506⋅7≡7(mod10)7^{2025} = 7^{4 \times 506 + 1} = (7^4)^{506} \cdot 7^1 \equiv 1^{506} \cdot 7 \equiv 7 \pmod{10}

So the last digit is 7. No need to compute 720257^{2025}.

The Rules

Modular arithmetic plays nice with addition, subtraction, and multiplication:

  • If a≡b(modn)a \equiv b \pmod{n} and c≡d(modn)c \equiv d \pmod{n}, then a+c≡b+d(modn)a+c \equiv b+d \pmod{n}
  • Same for subtraction and multiplication

Division is trickier. You can’t just divide both sides unless you’re careful.

Fermat’s Little Theorem

Here’s a powerful shortcut: if pp is prime and aa isn’t divisible by pp, then ap−1≡1(modp)a^{p-1} \equiv 1 \pmod{p}.

Want 5100 mod 75^{100} \bmod 7? Since 7 is prime and 5 isn’t divisible by 7, we know 56≡1(mod7)5^6 \equiv 1 \pmod{7}.

Since 100=6×16+4100 = 6 \times 16 + 4: 5100=(56)16⋅54≡116⋅54≡625≡2(mod7)5^{100} = (5^6)^{16} \cdot 5^4 \equiv 1^{16} \cdot 5^4 \equiv 625 \equiv 2 \pmod{7}

Done. No giant calculations.

Finding Patterns

Many competition problems involve finding patterns in powers. The key is to compute a few small powers, see the pattern, then use it.

For 2100 mod 72^{100} \bmod 7:

  • 21≡22^1 \equiv 2
  • 22≡42^2 \equiv 4
  • 23=8≡12^3 = 8 \equiv 1

Pattern repeats every 3. Since 100=3×33+1100 = 3 \times 33 + 1, the answer is 21≡22^1 \equiv 2.

Where You’ll See This

Base conversion shows up in:

  • Computer science (binary, hex)
  • Competition problems
  • Cryptography
  • Understanding how computers work

Modular arithmetic shows up in:

  • Competition problems (constantly)
  • Cryptography (RSA encryption)
  • Calendar calculations
  • Finding last digits, remainders, patterns

The Takeaway

Both topics seem abstract, but they’re incredibly practical. Base conversion helps you understand how numbers work at a fundamental level. Modular arithmetic makes impossible problems possible.

The key is recognizing when to use them. If a problem asks about remainders, last digits, or divisibility, think modular arithmetic. If it asks about number representations or computer-related math, think base conversion.

Practice both. They’ll save you time and make you look like a genius.

← Back to All Resources