Counting in Any Base
Watch the column weights re-scale from 1000-100-10-1 to 8-4-2-1, and hex stops being a separate system.
Skip to the animationA number written in any base is a set of columns whose weights are powers of that base, so converting between bases changes only the column weights — and because 8 and 16 are themselves powers of 2, octal and hexadecimal are regroupings of binary rather than conversions at all.
Positional notation, stated properly
3405 in base ten means 3×10³ + 4×10² + 0×10¹ + 5×10⁰. The only thing base ten contributes is the 10 in those powers. Replace it with any base b > 1 and every rule you already know still applies.
A base-b system has exactly b digits, running 0 to b−1. That is why binary has no digit 2, and why hexadecimal had to borrow A–F once it ran out of numerals.
Converting to a base: divide and keep remainders
- 1Divide the value by the target base. The remainder is the units column.
- 2Divide the quotient again. That remainder is the next column up.
- 3Continue until the quotient is zero.
- 4Read the remainders bottom to top — the first one you obtained was the smallest column.
For a fractional part you multiply instead and take the integer carry each time, reading top to bottom. 0.625 becomes 0.101 in three steps.
A fraction terminates in base b only when its denominator divides a power of b. Ten has a factor of 5 that two never will, so 0.1 repeats forever in binary — which is the origin of 0.1 + 0.2 ≠ 0.3 in almost every programming language.
Why octal and hexadecimal exist
16 = 2⁴ and 8 = 2³, so one hex digit corresponds to exactly four bits and one octal digit to exactly three, with no interaction between the groups. Conversion is therefore grouping, not arithmetic.
| Binary | Hex | Binary | Hex |
|---|---|---|---|
| 0000 | 0 | 1000 | 8 |
| 0001 | 1 | 1001 | 9 |
| 0010 | 2 | 1010 | A |
| 0011 | 3 | 1011 | B |
| 0100 | 4 | 1100 | C |
| 0101 | 5 | 1101 | D |
| 0110 | 6 | 1110 | E |
| 0111 | 7 | 1111 | F |
Group from the right, padding the leftmost group with zeros if it is short. Grouping from the left renumbers every column weight and produces a different number entirely.
So hexadecimal is not a rival number system. It is a compact, human-readable way of writing binary, which is why memory addresses, colour codes and machine instructions are all quoted in it.
Arithmetic, and the one shortcut worth knowing
Addition works exactly as in decimal: add column by column and carry when the total reaches the base. In binary 1 + 1 = 10 — write 0, carry 1.
Multiplying by the base shifts left and dividing by it shifts right, so in binary x << 1 is 2x and x >> 1 is x / 2. Compilers rely on this constantly, and it is free in hardware because a shift is just wiring.
The numbers you will be asked for
- Positional value
N = Σ dᵢ · bⁱ
dᵢ is the digit in column i, b the base.
- Digits available
0 to b − 1
Which is why base 16 needs six extra symbols.
- Range of n digits
0 to bⁿ − 1
Eight bits give 0 to 255.
- Grouping
1 hex digit ≡ 4 bits · 1 octal digit ≡ 3 bits
Group from the right, always.
Advantages and disadvantages
Advantages
- One rule — columns of powers — covers every base there is.
- Hex and octal group binary exactly, so conversion needs no arithmetic.
- Multiplying or dividing by the base is a shift, which is free in hardware.
- Any integer has an exact representation in any base.
Disadvantages
- Fractions that terminate in one base may repeat forever in another.
- Binary is unreadable at length, which is the entire reason hex is used.
- Grouping from the wrong end silently produces a different number.
- Decimal fractions have no exact binary form, so money is usually held in integers.
Watch it work
Check yourself
question 1 / 4
One question at a time. Pick an answer to see why it is right or wrong, then move on — there is no score to keep and nothing is saved.