Counting with a different number of symbols
You count in base 10 because you have ten fingers, not because ten is special. A digit's value depends on its position: 407 means 4×100 + 0×10 + 7×1. Change the base and only the place values change — the idea is identical.
A computer is built from switches, and a switch has two states. So it counts in base 2, where the place values are powers of two and the only digits are 0 and 1. Each digit is a bit, and eight bits make a byte.
Binary is correct but unreadable — a single byte takes eight characters to write. So programmers use base 16 (hexadecimal) as shorthand, because 16 is 2⁴ and each hex digit stands for exactly four bits. Base 8 (octal) does the same job three bits at a time.
| Base | Name | Digits used | Bits per digit |
|---|---|---|---|
| 2 | binary | 0, 1 | 1 |
| 8 | octal | 0–7 | 3 |
| 10 | decimal | 0–9 | — |
| 16 | hexadecimal | 0–9, A–F | 4 |
Switch to Hex and watch the dividers appear. Each group of four bits is one hex digit — no arithmetic is needed to convert, which is exactly why programmers write addresses in hex.
Converting between bases
Two methods cover every conversion the paper asks for, and both are short once you have practised them.
To go from any base to decimal, multiply each digit by its place value and add. To go from decimal to any base, divide repeatedly by the base and read the remainders upwards.
Convert 10110₂ to decimal, and 45₁₀ to binary.
- Place values for 5 bits are 16, 8, 4, 2, 1.Write them above the digits before doing anything else — it prevents the commonest error, misaligning the columns.
1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 16 + 4 + 2 = 22.Only the positions holding a 1 contribute anything.- For 45, divide repeatedly by 2: 45→22 r1, 22→11 r0, 11→5 r1, 5→2 r1, 2→1 r0, 1→0 r1.Keep dividing until the quotient reaches zero.
- Read the remainders bottom to top:
101101₂.Reading them downwards instead gives 101101 reversed, which is the standard mistake. Check: 32+8+4+1 = 45 ✓
10110₂ = 22₁₀; 45₁₀ = 101101₂
Binary to hex needs no arithmetic at all
Group the bits in fours from the right, padding the left with zeros if needed, and replace each group with its hex digit. 10110101 becomes 1011 0101 becomes B5. Going through decimal in between is slower and introduces errors. For octal, group in threes instead.
Representing more than numbers
A computer stores everything as binary, so text, colours and sound all have to be turned into numbers first. The rule for doing so is a code, and it is agreed in advance so that two machines interpret the same bits the same way.
ASCII uses 7 bits to give 128 characters — enough for English letters, digits and punctuation. That is not enough for the world's writing systems, so Unicode extends the idea to over a million code points, covering Urdu, Arabic, Chinese and emoji. UTF-8 is the encoding of Unicode used by almost all web pages.
The character "5" is not the number 5
In ASCII the character 5 is stored as 53, not as 5. That is why adding two numbers typed by a user gives nonsense unless they are converted from text to numbers first — and it is the reason programming languages distinguish the string "5" from the integer 5.
Binary arithmetic
Adding in binary follows the same column rules as decimal, with one difference: you carry at 2 rather than at 10. There are only four cases to know: 0+0=0, 0+1=1, 1+0=1, and 1+1=10 — that is, zero carry one.
A fixed number of bits can only hold so much. Adding two 8-bit numbers whose total exceeds 255 produces a carry out of the last column with nowhere to go — an overflow, and the stored answer is simply wrong. Real hardware sets a flag when this happens so the program can react.
Add 01011010 and 00110110 in binary, and check the answer in decimal.
- Right-hand column:
0 + 0 = 0. Next:1 + 1 = 10, write 0 carry 1.Work right to left exactly as in decimal addition. - Continue column by column, adding any carry: the result is
10010000.Keep the carries written above the columns; doing them mentally is where errors appear. - Check:
01011010 = 90and00110110 = 54.64+16+8+2 = 90 and 32+16+4+2 = 54. 90 + 54 = 144, and10010000 = 128 + 16 = 144✓Converting both sides to decimal is a complete check and takes thirty seconds.
10010000₂ = 144₁₀
Before you leave this chapter
- Place value works in every base; only the powers change.
- Any base to decimal: multiply by place values and add. Decimal to any base: divide repeatedly, read remainders upwards.
- Binary to hex: group bits in fours from the right. To octal: group in threes.
- n bits give 2ⁿ values. 1 byte = 8 bits.
- ASCII is 7-bit and English-only; Unicode covers every script. The character "5" is not the number 5.