Computer ScienceFoundation20 min read

Number Systems

Why a machine that only knows two symbols can represent anything

This topic appears in:

01

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.

BaseNameDigits usedBits per digit
2binary0, 11
8octal0–73
10decimal0–9
16hexadecimal0–9, A–F4

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.

02

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.

Worked example

Convert 10110₂ to decimal, and 45₁₀ to binary.

  1. 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.
  2. 1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 16 + 4 + 2 = 22.Only the positions holding a 1 contribute anything.
  3. 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.
  4. 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.

03

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.

n bits represent 2ⁿ different values1 byte = 8 bits1 KB = 1024 bytes1 MB = 1024 KB1 GB = 1024 MBthe 2ⁿ rule answers most "how many can you represent" questions in one line

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.

04

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.

Worked example

Add 01011010 and 00110110 in binary, and check the answer in decimal.

  1. Right-hand column: 0 + 0 = 0. Next: 1 + 1 = 10, write 0 carry 1.Work right to left exactly as in decimal addition.
  2. 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.
  3. Check: 01011010 = 90 and 00110110 = 54.64+16+8+2 = 90 and 32+16+4+2 = 54.
  4. 90 + 54 = 144, and 10010000 = 128 + 16 = 144Converting both sides to decimal is a complete check and takes thirty seconds.

10010000₂ = 144₁₀

Before you leave this chapter

  1. Place value works in every base; only the powers change.
  2. Any base to decimal: multiply by place values and add. Decimal to any base: divide repeatedly, read remainders upwards.
  3. Binary to hex: group bits in fours from the right. To octal: group in threes.
  4. n bits give 2ⁿ values. 1 byte = 8 bits.
  5. ASCII is 7-bit and English-only; Unicode covers every script. The character "5" is not the number 5.

Practice questions

6 questions · 20 marks · full working on every one

Try each one on paper first, then open the working. The marks are shown where they are actually awarded, because that is where they are actually lost.

Short questions

3 · 6 marks

Two marks each, in the style of the short-question section of the paper. Answer in two or three lines.

SQ1[2 marks]
Why do computers use the binary number system?
Model answer

A computer is built from electronic switches, each of which has only two reliable states — on and off, or high and low voltage. Binary has exactly two digits, so each digit maps directly onto one switch, making the hardware simple and resistant to electrical noise.

Examiner tip. Tie it to the hardware. "Because computers only understand 0 and 1" restates the question rather than answering it.

SQ2[2 marks]
Convert 11010₂ to decimal.
Model answer

Place values 16, 8, 4, 2, 1: 16 + 8 + 0 + 2 + 0 = 26.

Examiner tip. Write the place values above the digits first. Nearly every wrong answer here comes from misaligned columns, not from arithmetic.

SQ3[2 marks]
State one advantage of hexadecimal over binary for a programmer.
Model answer

It is far shorter and easier to read — one hex digit replaces four bits, so a 32-bit address takes 8 hex characters instead of 32 binary ones — while converting between the two needs no arithmetic at all.

Examiner tip. Both halves earn credit: the brevity and the fact that conversion is direct. Mentioning only "it is shorter" often scores one.

Solved numericals

2 · 8 marks

Full working, one step per line, with the marks shown where they are awarded.

N1[4 marks]
Convert 2C₁₆ to binary and then to decimal.
Full working
  1. 2 in hex is 0010 in binaryfour bits per hex digit[1]
  2. C is 12 in decimal, which is 1100A=10, B=11, C=12, D=13, E=14, F=15[1]
  3. Together: 00101100₂concatenate the groups, do not add them[1]
  4. Decimal: 32 + 8 + 4 = 44or 2×16 + 12 = 44 directly from hex[1]

2C₁₆ = 00101100₂ = 44₁₀

Examiner tip. Converting hex straight to decimal (2×16 + 12) is a useful check on the binary route. If the two disagree, one of the four-bit groups is wrong.

N2[4 marks]
Add the 8-bit binary numbers 11001010 and 01110011. State whether overflow occurs.
Full working
  1. Adds column by column from the right, carrying where a column totals 2[1]
  2. Result within 8 bits: 01000010 with a carry out of the leftmost column[1]
  3. In decimal 202 + 115 = 317, which exceeds the 8-bit maximum of 255[1]
  4. Overflow occurs — the true answer needs 9 bits, so the stored 8-bit result is incorrectthe consequence must be stated[1]

Carry out of the final column; overflow occurs because 317 > 255.

Examiner tip. Always convert both operands to decimal as a check. If the total exceeds 255 for 8 bits, overflow is certain before you add a single column.

Long questions

1 · 6 marks

Theory and numerical together, as they appear in the long-question section.

LQ1[6 marks]
A system stores text using ASCII and images using 24-bit colour.
  1. How many different characters can 7-bit ASCII represent, and why is this insufficient for Urdu?
  2. How many distinct colours can 24-bit colour represent?
  3. Calculate the file size in KB of an uncompressed 100 × 200 pixel image in 24-bit colour.
Mark scheme
  1. 2⁷ = 128 characters[1]
  2. Urdu uses a different script with many additional letterforms, and 128 slots are already taken by English letters, digits and punctuation — so Unicode is used insteadnaming Unicode expected[1]
  3. 2²⁴ = 16 777 216 coloursaccept "about 16.7 million"[1]
  4. Total pixels = 100 × 200 = 20 000[1]
  5. Each pixel takes 24 bits = 3 bytes, so 20 000 × 3 = 60 000 bytesconverting bits to bytes is the step most often missed[1]
  6. 60 000 / 1024 = 58.6 KBaccept 58.6 or 60 KB if 1000 bytes per KB is stated[1]

(a) 128, too few for a second script (b) 16 777 216 (c) about 58.6 KB

Examiner tip. File-size questions always follow the same chain: pixels × bits per pixel → bits → bytes → KB. Write each conversion on its own line and the marks follow the working.