Skip to content
Tutorials Center
My learning

Topics

Lesson 8 of 86 ยท Number System

Number Puzzles and Number Bases

Solve digit problems and cryptarithms, then convert between decimal, binary, octal and hexadecimal with a runnable base converter and worked examples.

Aptitude papers love questions that treat a number as a row of digits: "a two-digit number is four times the sum of its digits", "the number exceeds its reverse by 27", or a sum in which letters stand for digits. They all rest on one idea, place value. Once you write 10a + b instead of "the number", the puzzle becomes ordinary algebra.

The same idea explains number bases. We count in base 10 because we have ten fingers; computers count in base 2, and programmers use base 8 and base 16 as compact shorthand. In this lesson you will solve classic digit problems, reason about cryptarithms, and convert between bases quickly.

Writing numbers with digits

A two-digit number with tens digit a and units digit b has the value 10a + b. Its reverse is 10b + a. A three-digit number abc is 100a + 10b + c. Two facts follow immediately and are worth memorizing:

  • A two-digit number plus its reverse is 11(a + b), so it is always a multiple of 11.
  • A two-digit number minus its reverse is 9(a - b), so it is always a multiple of 9.
  • For three digits, abc - cba = 99(a - c); the tens digit cancels.

Example 1. The digits of a two-digit number add up to 11, and the number exceeds its reverse by 27. Find it.

Difference: 9(a - b) = 27, so a - b = 3. With a + b = 11, adding the two equations gives 2a = 14, so a = 7 and b = 4. The number is 74. Check: 74 - 47 = 27. โœ“

Example 2. A two-digit number is 4 times the sum of its digits, and the product of the digits is 18. Find it.

10a + b = 4(a + b) gives 6a = 3b, so b = 2a. The candidates are 12, 24, 36 and 48. Only 36 has digit product 3 ร— 6 = 18. Also 36 = 4 ร— 9. โœ“

Example 3. How many two-digit numbers equal 7 times the sum of their digits?

10a + b = 7a + 7b gives 3a = 6b, so a = 2b. With b = 1, 2, 3, 4 we get 21, 42, 63 and 84 (and b = 5 would need a = 10). That is 4 numbers.

Example 4. A three-digit number has hundreds digit 3 more than its units digit. How much larger is it than its reverse?

99(a - c) = 99 ร— 3 = 297, whatever the other digits are.

Counting digit patterns. How many three-digit numbers have all different digits? The hundreds digit has 9 choices (1 to 9), the tens digit has 9 (any digit except the one used, including 0), and the units digit has 8. So 9 ร— 9 ร— 8 = 648.

Cryptarithms

A cryptarithm (or alphametic) replaces digits with letters. The same letter always means the same digit, different letters mean different digits, and the leading letter of a number cannot be 0. The most famous example is:

TEXT
    S E N D
  + M O R E
  ---------
  M O N E Y

Hand-solving uses column reasoning:

  1. Two four-digit numbers add to less than 20,000, so the carry into the fifth column is at most 1. M is a new leading digit, so M = 1.
  2. In the thousands column, S + M + carry must produce O and a carry of 1 (to make M). With M = 1: S + 1 + c = 10 + O. If S = 9 and c = 0, then O = 0. If S = 8 and c = 1, then O = 0. If S = 9 and c = 1, then O = 1, which clashes with M. So O = 0.
  3. The remaining columns need a little trial, and after that the whole puzzle falls out.

For anything beyond two or three steps, a short program that tries every assignment is the safest tool. The solver below tries all digit assignments for the letters, skipping zero for leading letters. It first shows a puzzle with several answers, then the famous one with a single answer.

JS A brute-force cryptarithm solver

Press Run (or Ctrl + Enter) to see the console output here.

No output.

A well-posed exam cryptarithm has exactly one solution. TWO + TWO = FOUR is not well-posed (it has seven), which is why an exam would add a clue such as "F = 1 and R = 6" or "the digit O is even".

Number bases

In base b there are b digits, from 0 to b - 1, and each place is worth a power of b. Base 10 has places 1, 10, 100, ...; base 2 has places 1, 2, 4, 8, ...; base 16 has places 1, 16, 256, ... Because base 16 needs digits beyond 9, we use A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.

Base Name Digits Typical use
2 binary 0, 1 how hardware stores numbers
8 octal 0 to 7 file permissions
10 decimal 0 to 9 everyday counting
16 hexadecimal 0 to 9, A to F colors, memory addresses

To decimal

Multiply each digit by its place value and add. For binary 1011010:

64 + 16 + 8 + 2 = 90 (the places with a 1 are 64, 16, 8 and 2).

From decimal

Divide repeatedly by the base and read the remainders from bottom to top.

flowchart TD
    A["90 รท 16 = 5 remainder 10 (A)"] --> B["5 รท 16 = 0 remainder 5"]
    B --> C["Read remainders upward: 5 then A"]
    C --> D["90 in decimal = 5A in hexadecimal"]

Dividing 90 by 16 gives the digits of 5A, because 5 ร— 16 + 10 = 90.

Shortcuts between binary, octal and hex

Because 8 is 2^3 and 16 is 2^4, you can skip decimal altogether. Group binary digits in threes from the right for octal, in fours for hexadecimal:

  • 1011010 grouped in threes: 001 011 010, which is octal 1 3 2, so 132 in base 8 (check: 64 + 24 + 2 = 90).
  • 1011010 grouped in fours: 0101 1010, which is hex 5 A, so 5A.

Arithmetic in other bases

Do it as in decimal but carry when you reach the base. Binary: 1 + 1 = 10, so 1101 + 1011 gives 11000 (that is 13 + 11 = 24).

Finding an unknown base

Write both sides in decimal, using b for the unknown.

  • 32 in base b equals 26 in decimal: 3b + 2 = 26, so b = 8.
  • 4 ร— 6 = 30 is true in base b: the left side is 24, the right side is 3b, so b = 8.
  • 100 in base b equals 49: b^2 = 49, so b = 7.

The converter below shows the repeated-division steps and checks them against JavaScript's built-in parseInt.

JS Base converter with working shown

Press Run (or Ctrl + Enter) to see the console output here.

No output.

An n-bit binary number can represent 2^n values, from 0 to 2^n - 1. So 8 bits give 0 to 255, which is why a color channel in hex runs from 00 to FF.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. The digits of a two-digit number add up to 9, and the number is 27 more than its reverse. What is the number?

    9(a - b) = 27 gives a - b = 3. With a + b = 9, a = 6 and b = 3, so the number is 63. Check: 63 - 36 = 27.
  2. 2. What is 1101 in binary written in decimal?

    8 + 4 + 0 + 1 = 13.
  3. 3. Convert decimal 90 to hexadecimal.

    90 = 5 ร— 16 + 10, and 10 is the digit A, so the hex value is 5A.
  4. 4. In which base is the equation 4 ร— 6 = 30 correct?

    In decimal the left side is 24. The right side, 30 in base b, equals 3b. So 3b = 24 and b = 8.
  5. 5. How many three-digit numbers have three different digits?

    9 choices for the hundreds digit (1 to 9), 9 for the tens digit (0 to 9 except the one used) and 8 for the units: 9 ร— 9 ร— 8 = 648.

Summary

  • Write digit problems as 10a + b (two digits) or 100a + 10b + c (three digits) and solve the algebra.
  • A number plus its reverse is a multiple of 11; a number minus its reverse is a multiple of 9.
  • Cryptarithms need column reasoning (carries and leading digits); a short program checks every possibility.
  • Base b uses digits 0 to b - 1; hex uses A to F for 10 to 15.
  • Convert to decimal by place values, from decimal by repeated division (read remainders upward), and between binary, octal and hex by grouping bits in threes or fours.
  • To find an unknown base, convert both sides to decimal and solve for b.

Next: Percentages, the first topic in the chapter on percentages, ratio and proportion.