Data Representation 🔢
Your photos, your playlists, the Thai on your keyboard — to a computer it's all just 1s and 0s. This chapter is how that actually works.
🎯 What you'll unlock this chapter
- 🔢 Why computers use binary, and how to convert between binary, denary and hexadecimal
- ➕ Adding 8-bit binary numbers, spotting overflow, and doing logical shifts
- ➖ Storing negative numbers with two's complement
- 🔤 How text, sound and images become binary
- 💾 Measuring storage, calculating file sizes, and lossy vs lossless compression
- ✏️ All 16 activities from the coursebook as auto-marked practice — new questions every time
💡 Why binary? 1.1.1
A computer is built from millions of tiny electronic switches (transistors inside logic gates). A switch only has two states — ON or OFF — so we write them as 1 and 0. That's binary: a number system with just two digits.
So any data — numbers, text, pictures, sound, instructions — has to be converted into binary before a computer can store or process it.
🧮 Denary vs binary vs hex 1.1.2
Every number system works the same way — each column is worth the base times the column to its right.
| System | Base | Digits used | Column values (right → left) |
|---|---|---|---|
| Denary | 10 | 0–9 | 1, 10, 100, 1000 … |
| Binary | 2 | 0, 1 | 1, 2, 4, 8, 16, 32, 64, 128 … |
| Hexadecimal | 16 | 0–9, A–F | 1, 16, 256, 4096 … |
Binary → denary: add up the columns that have a 1
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
11101110 = 128 + 64 + 32 + 8 + 4 + 2 = 238
Denary → binary: two methods (both give the same answer)
Method 1 · Subtract powers of 2
Take away the biggest column value that fits, put a 1 there, repeat until you hit 0.
142 → binary 142 − 128 = 14 128 ✓ 14 − 8 = 6 8 ✓ 6 − 4 = 2 4 ✓ 2 − 2 = 0 2 ✓ = 1000 1110
Method 2 · Divide by 2
Keep dividing by 2, write each remainder, then read the remainders bottom to top.
142 ÷ 2 = 71 r 0 71 ÷ 2 = 35 r 1 35 ÷ 2 = 17 r 1 17 ÷ 2 = 8 r 1 8 ÷ 2 = 4 r 0 4 ÷ 2 = 2 r 0 2 ÷ 2 = 1 r 0 1 ÷ 2 = 0 r 1 ↑ read upwards = 1000 1110
🎮 Bit Lab — flip the switches
Tap any bit to turn it on or off, or type a denary number (0–255). Watch all three number systems update together.
🔣 Hexadecimal 1.1.2
Hex is base 16, so it needs 16 digits. After 9 we run out of normal digits, so we use letters: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
The magic part: one hex digit = exactly four bits (a nibble). That makes binary ↔ hex conversion super quick.
| Hex | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Denary | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Binary → hex
Split into groups of 4 from the right (pad the left with 0s), then swap each group for its hex digit.
1011 1110 0001
B E 1 → BE1 Hex → binary
Swap each hex digit for its 4-bit group.
4 5 A
0100 0101 1010 → 0100 0101 1010 Hex → denary
Multiply each digit by its column value (1, 16, 256 …) and add.
45A = 4×256 + 5×16 + 10×1
= 1024 + 80 + 10
= 1114 Denary → hex
Keep dividing by 16; read the remainders bottom to top (10–15 become A–F).
2004 ÷ 16 = 125 r 4 125 ÷ 16 = 7 r 13 → D 7 ÷ 16 = 0 r 7 = 7D4
🌐 Where is hex actually used? 1.1.3
Computers still work in binary — hex is just for humans. It's shorter, easier to read and copy, and you're much less likely to make a mistake with D2AF than with 1101 0010 1010 1111.
| Use | What it looks like | Notes |
|---|---|---|
| Error codes | 0x0000007B | Refer to the memory location where the error happened; help programmers debug. Memory dumps are shown in hex too. |
| MAC addresses | 00-1C-B3-4F-25-FE | 48 bits as 6 pairs of hex digits. First half = manufacturer ID, second half = device serial number. Uniquely identifies a device's network interface card. |
| IPv6 addresses | 2001:0db8:85a3:0000:0000:8a2e:0370:7334 | 128 bits as 8 groups of 4 hex digits, separated by colons. (IPv4 is 32 bits, usually written in denary.) |
| HTML colour codes | #FF8000 | Two hex digits each for Red, Green, Blue — each 00 to FF (0–255). |
🎨 HTML colour mixer
Each colour channel is one byte (0–255), so it fits in exactly two hex digits.
➕ Adding binary numbers 1.1.4
Same as column addition in denary — work from the right, carry when a column gets too big. In binary, "too big" means anything over 1.
| Add | Result | Write down | Carry |
|---|---|---|---|
| 0 + 0 | 0 | 0 | 0 |
| 0 + 1 | 1 | 1 | 0 |
| 1 + 1 | 2 | 0 | 1 |
| 1 + 1 + 1 | 3 | 1 | 1 |
126 + 62 carry 1 1 1 1 1 1 0 1 1 1 1 1 1 0 (126) + 0 0 1 1 1 1 1 0 ( 62) ───────────────────── 1 0 1 1 1 1 0 0 (188 ✓)
💥 Overflow 1.1.4
An 8-bit register can hold at most 1111 1111 = 255 (that's 2⁸ − 1). If an addition needs a 9th bit, it doesn't fit — that's an overflow error.
110 + 222 = 332 … but 332 > 255 0 1 1 0 1 1 1 0 (110) + 1 1 0 1 1 1 1 0 (222) ───────────────────── 1 0 1 0 0 1 1 0 0 ← 9th bit! 8 bits left = 76 ✗
🧮 Binary Adder
Pick two denary numbers (0–255). The carries are shown in yellow — try to make it overflow.
↔️ Logical shifts 1.1.5
A logical shift slides every bit left or right. The empty spaces are filled with 0s, and any bit pushed off the end is lost.
0001 0101 (21) → 0010 1010 (42)
1100 1000 (200) → 0110 0100 (100)
Shift n places = multiply or divide by 2ⁿ. So 2 places left = × 4, 3 places right = ÷ 8.
- 🔝 Most significant bit (MSB) — the left-most bit (biggest value).
- 🔚 Least significant bit (LSB) — the right-most bit (worth 1).
- ⚠️ If a 1 falls off either end, the answer is wrong: off the left = the result was too big; off the right = you've lost precision (e.g. 25 ÷ 2 can't be 12.5 in whole-number binary).
🎮 Shift Lab
Start with 21, shift left a few times, and watch for the moment it breaks.
➖ Negative numbers: two's complement 1.1.6
So far every number has been positive. To store negatives, two's complement makes one tiny change: the left-most column is worth −128 instead of 128.
| −128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|
| 1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 |
1011 1101 = −128 + 32 + 16 + 8 + 4 + 1 = −67
- 🚦 The left-most bit tells you the sign: 0 = positive, 1 = negative.
- 📏 8-bit range: −128 (1000 0000) to +127 (0111 1111).
- ✅ Positive numbers look exactly the same as normal binary — just keep the −128 column as 0.
🔄 Denary → negative binary (two methods)
Method 1 · Build it from −128
Put a 1 in the −128 column, then work out what you need to add back.
−79 = −128 + 49 49 = 32 + 16 + 1 −128 64 32 16 8 4 2 1 1 0 1 1 0 0 0 1 = 1011 0001
Method 2 · Invert and add 1
Write the positive version, flip every bit, then add 1.
−79 +79 0100 1111 invert 1011 0000 add 1 + 0000 0001 ───────── 1011 0001
Negative binary → denary
Just add the column values as usual, remembering the first column is −128:
1110 0100 = −128 + 64 + 32 + 4 = −28
1111 0101 = −128 + 64 + 32 + 16 + 4 + 1 = −11
🎮 Two's Complement Lab
The red column is −128. Type any number from −128 to 127, or hit Invert + 1 to flip its sign.
🗣️ Discussion point
Press Invert + 1 on 1000 0000 (−128) in the lab above. What happens, and why can't 8-bit two's complement store +128?
🔤 Representing text 1.2.1
Every key on your keyboard has a number. When you type, the computer stores the number (in binary), not the letter. The full list of characters and their codes is called a character set.
| ASCII | Extended ASCII | Unicode | |
|---|---|---|---|
| Bits per character | 7 | 8 | up to 32 (1–4 bytes) |
| Number of characters | 128 (0–127) | 256 (0–255) | over a million possible |
| Covers | English letters, digits, symbols + 32 control codes | adds some non-English letters & graphics | every world language — Thai, Chinese, Arabic … plus emoji 😎 |
| Main downside | Can't represent most non-Western languages | Uses more bits per character → bigger files | |
- 🔗 Unicode's first 128 codes are the same as ASCII, so old English text still works.
- 🔠 Uppercase and lowercase differ by exactly one bit (the one worth 32): A = 65 = 0100 0001, a = 97 = 0110 0001.
- 🗂️ Codes are in order (A, B, C … and 0–9 together), which makes sorting and searching easy.
🎮 Text Encoder
Type anything — try English, then some Thai. Watch what ASCII can and can't handle.
Your text, encoded
ASCII table · printable characters 32–127
Find a character by its column (first hex digit) and row (second hex digit) — A is column 4, row 1 → hex 41 = denary 65. Codes 0–31 are invisible control codes like Tab and Enter. Tap any character to type it.
🎵 Representing sound 1.2.2
Sound is a wave of vibrations that varies continuously — it's analogue. Computers only handle digital data, so an analogue-to-digital converter (ADC) samples the wave: it measures the amplitude (height) at regular time intervals and stores each measurement as a binary number.
Higher sampling rate or resolution → recording is closer to the original sound → but the file is bigger and takes longer to transfer.
🎮 Sampling Visualiser
The grey line is the real sound wave. The green steps are what gets stored. Crank the settings down and watch the quality fall apart.
🖼️ Representing images 1.2.3
A bitmap image is a grid of tiny dots called pixels (picture elements). Each pixel's colour is stored as a binary number.
| Colour depth | Colours | Example |
|---|---|---|
| 1 bit | 2¹ = 2 | Black and white only |
| 8 bits | 2⁸ = 256 | Old games, GIFs |
| 24 bits | 2²⁴ = 16 777 216 | Modern screens — 8 bits each for R, G, B |
- ⬆️ Higher resolution → more detail, sharper image.
- 🟫 Too low → the image looks pixelated (blocky).
- 📦 Higher resolution or colour depth → bigger file → fewer photos fit in storage and they take longer to upload/download.
📏 Measuring storage 1.3.1
Memory is measured in powers of 2, so the IEC binary units are the accurate ones (and the ones Cambridge uses).
| Unit | Equals | Power of 2 |
|---|---|---|
| bit | a single 1 or 0 | — |
| nibble | 4 bits | — |
| byte | 8 bits | — |
| kibibyte (KiB) | 1024 bytes | 2¹⁰ |
| mebibyte (MiB) | 1024 KiB = 1 048 576 bytes | 2²⁰ |
| gibibyte (GiB) | 1024 MiB | 2³⁰ |
| tebibyte (TiB) | 1024 GiB | 2⁴⁰ |
| pebibyte (PiB) | 1024 TiB | 2⁵⁰ |
| exbibyte (EiB) | 1024 PiB | 2⁶⁰ |
🧾 Calculating file size 1.3.2
🖼️ Image
size (bits) = width × height × colour depth 2048 × 2048 pixels, 16-bit colour 2048 × 2048 × 16 = 67 108 864 bits ÷ 8 = 8 388 608 bytes ÷ 1024 = 8192 KiB ÷ 1024 = 8 MiB
🎵 Sound
size (bits) = sample rate × resolution × seconds
(× 2 for stereo)
60 min CD audio: 44 100 Hz, 16-bit, stereo
44 100 × 16 × 3600 × 2 = 5 080 320 000 bits
÷ 8 = 635 040 000 bytes
÷ 1024 ÷ 1024 ≈ 605.6 MiB 🎮 File Size Calculator
🗜️ Why compress? 1.3.3
As you just calculated, images and sound get huge. Compressing files:
- 💽 saves storage space on devices
- ⚡ makes files faster to send, upload, download and stream
- 📶 uses less bandwidth on a network
- 💸 reduces the cost of storage and data transfer
⚖️ Lossy vs lossless 1.3.4
✂️ Lossy
Permanently removes data that's judged unnecessary. The original file can't be rebuilt.
- 🎵 MP3 — drops sounds outside human hearing, and quieter sounds played at the same time as louder ones (perceptual music shaping). Around 90% smaller.
- 🎬 MP4 — the same idea for video, photos and animation as well as sound.
- 📷 JPEG — takes advantage of the eye not noticing tiny colour differences, and being more sensitive to brightness than to colour.
- 📉 Can also reduce resolution, colour depth or sampling rate.
🔒 Lossless
Shrinks the file so that every bit of the original can be perfectly rebuilt.
- 📊 Essential where losing data would be a disaster — text, spreadsheets, program files.
- 🔁 Run-length encoding (RLE) — replaces a run of identical items with how many + what.
- 📦 Files end up bigger than with lossy compression.
How RLE works
aaaaabbbbccddddd → 16 bytes count, ASCII code: 05 97 04 98 02 99 05 100 → 8 bytes (50% smaller)
RLE is great when there are long runs (like big blocks of one colour in an image) — but on text like cdcdcdcd it makes things bigger. Real RLE uses a special flag value to mark where a run starts, so single characters don't need a count.
🎮 RLE Compressor
Type a string (ASCII letters only) and see whether RLE actually helps.
✏️ Practice hub 16 activities · every example
Every activity from the coursebook chapter, as an auto-marked practice set. Same skill as the book's activity with the same number — but fresh numbers every time you hit 🔀 New questions, so you can keep going until it's easy.
📘 Worked examples
Every type of worked example in the chapter, solved step by step. Hit 🔀 Another example on any of them for a new one.
🃏 Key-term flashcards Tap to flip
🧠 Mini-quiz
📝 Exam-style questions Try, then peek
- ✅ Computers are made of millions of switches / transistors / logic gates…
- ✅ …which only have two states, ON and OFF, represented by 1 and 0.
- 🧮 (a) 64 + 32 + 8 + 1 = 105
- 🔣 (b) 0110 = 6, 1001 = 9 → 69
0101 1101 ( 93)
+ 1011 0110 (182)
───────────
1 0001 0011 - 💥 A 9th bit is generated → overflow error.
- 📏 93 + 182 = 275, which is greater than 255, the largest value 8 bits can hold. The register would wrongly hold 0001 0011 (19).
- ⬅️ 0011 0100 (52) shifted 2 left → 1101 0000 (208) = 52 × 4 ✓. No 1s lost.
- ➡️ 1101 0000 shifted 3 right → 0001 1010 (26) = 208 ÷ 8 ✓. Only 0s fell off the right, so still correct.
+45 0010 1101
invert 1101 0010
add 1 + 0000 0001
1101 0011
check: −128 + 64 + 16 + 2 + 1 = −45 ✓ 800 × 600 × 24 = 11 520 000 bits
÷ 8 = 1 440 000 bytes
÷ 1024 ≈ 1406.25 KiB
÷ 1024 ≈ 1.37 MiB - 📊 (a) Lossless — every value in the spreadsheet must be exactly as it was; losing any data would make it wrong/unusable.
- 🎬 (b) Lossy (e.g. MP4) — a much smaller file, quicker to send; the small loss of quality isn't noticeable to the human eye/ear.
🚀 Going further A Level preview
These two aren't on the IGCSE / O Level syllabus — they're the coursebook's extension topics for anyone heading to AS & A Level. Same skills, pushed one step further.