Type a branch, a subject or a topic — “round robin”, “paging”, “civil”.

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 animation

A 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

  1. 1Divide the value by the target base. The remainder is the units column.
  2. 2Divide the quotient again. That remainder is the next column up.
  3. 3Continue until the quotient is zero.
  4. 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.

BinaryHexBinaryHex
0000010008
0001110019
001021010A
001131011B
010041100C
010151101D
011061110E
011171111F

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

loading visualisation…

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.

Why can one hex digit be converted to four bits by inspection, with no arithmetic?
Converting 11 to binary by repeated division gives remainders 1, 1, 0, 1 in that order. What is the answer?
Why does 0.1 have no exact binary representation?
Why must binary be grouped into hex digits starting from the right?

0 / 4

4 still unanswered — the dots above jump straight to them.