Number bases: binary, denary and hexadecimal

A-Level Computer Science · Data Representation: Number Bases, Binary Arithmetic and Character Sets

Place value is the whole idea

In any base, each column is the base times the column to its right. In binary the columns are $128, 64, 32, 16, 8, 4, 2, 1$. To read a binary number, add the column values wherever there is a $1$. There is nothing to memorise beyond the doubling.

Denary to binary

Work from the left: take the largest column that fits, subtract, repeat. For $180$: $128$ fits (leaves $52$), $64$ does not, $32$ fits (leaves $20$), $16$ fits (leaves $4$), $8$ does not, $4$ fits (leaves $0$). Result $10110100$. This is more reliable under exam pressure than repeated division.

Hexadecimal is just grouped binary

Each hex digit is exactly four bits, so conversion is done by splitting into nibbles: $1011\,0100 \to B\,4 \to$ $\text{B4}$. That is why hex exists — it makes long binary readable without changing the value. Never convert binary$\to$denary$\to$hex; go straight through nibbles.

Why programmers use hex

Colour codes, memory addresses and MAC addresses are all hex because one hex digit replaces four bits, so a $32$-bit address becomes eight readable characters instead of thirty-two.

Gia tri theo hang cua mot byte112806413211608140201128 + 32 + 16 + 4 = 180Cong gia tri cua nhung cot mang bit 1 — khong hoc thuoc bang nao caHex: 1011 = B, 0100 = 4 → B4
Draw this exact place-value row in the corner of your scratch paper as soon as you enter the exam room. Every Paper 1 conversion question can be solved with it, and it also prevents miscounting the number of bits.

Worked example: three-way conversion and cross-checking

An $8$-bit register holds the hex value $\text{9C}$.

(a) Write the value in binary. (b) Write it in decimal. (c) Check your result using a different route.

Solution

(a) Split each hex digit into four bits: $9 = 1001$, $\text{C} = 1100$. Put them together: $10011100$.

(b) Add the values of the columns that hold a $1$ bit: $128 + 16 + 8 + 4 = 156$.

(c) A different check: compute directly from the hex: $9 \times 16 + 12 = 144 + 12 = 156$ ✓. Two different routes give the same number, so you can be confident.

Exam tip: always check by order of magnitude. An $8$-bit number lies between $0$ and $255$; if you get $1560$, you have certainly misplaced a column somewhere.

Common mistake

Dropping the leading $0$ when splitting into groups of four bits. The hex digit $9$ must be written as $1001$, not as $1001$ shortened to $1001$, but $\text{C}$ is very often written as $110$ (three bits). Each hex digit always gives EXACTLY four bits, even when the first bit is $0$: $3 \to 0011$, not $11$.

Key takeaway

One place-value row $128\ldots1$ solves every conversion question. Hex ↔ binary goes through groups of four bits, not by detouring through decimal. And always check against the sensible range for the number of bits in use.

All A-Level Computer Science lessons · Practice A-Level Computer Science questions (free, instant scoring) · Binary arithmetic, two's complement and overflow →