A1.2.2 · Data representation and computer logic
How binary stores data
By the end you can
Store integers (including two's complement), text, images, sound and video in binary, calculate how much space they need, and explain how the encoding affects storing and retrieving data.
A1.2.1 showed how to write numbers in binary. But a computer stores far more than numbers: text, photos, music, video. The trick is always the same: agree on a rule that turns the thing into numbers, then store the numbers in binary. The bits themselves carry no meaning. The same byte can be a number, a letter or a shade of grey, depending only on how a program reads it.
As an unsigned integer
65
As two's complement
65
As an ASCII character
"A"
As a grey pixel
Whole numbers#
An is plain binary, as in A1.2.1: n bits store 0 to 2ⁿ − 1. To store negative numbers too, almost every computer uses . The idea is simple: the leftmost bit is worth minus its place value. In 8 bits it is worth −128 instead of +128, so:
00000101= 4 + 1 = 5 (leftmost bit 0, an ordinary positive number)11111011= −128 + 64 + 32 + 16 + 8 + 2 + 1 = −5
So any number starting with 1 is negative, and 8 bits cover −128 to +127.
Write the positive version
−5 → start from 5 = 00000101Flip every bit
00000101 → 11111010Add 1
11111010 + 1 = 11111011. That is −5.
Range: -128 to 127(unsigned would be 0 to 255)
The leftmost bit is worth -128, so when it is 1 the number is negative.
Denary → two's complement
For a negative number: write the positive version, flip every bit, then add 1.
Working
- 75 in 8 bits = 01001011
- Flip every bit: 10110100
- Add 1: 10110101
Two's complement → denary
Add the place values of every 1, counting the leftmost as negative.
Working
- -128 + 32 + 16 + 4 + 1 = -75
As two's complement
-75
Same bits, unsigned
181
Why this odd rule? Because ordinary binary addition then just works for negative numbers too: the ALU needs no separate circuit for subtraction, it adds the two's complement instead. And there is only one zero. The cost is a lopsided range: −128 has no +128 to match it in 8 bits.
1101
Two's complement -3 · unsigned 13
−8 + 4 + 1 = -3
Green half: leftmost bit 0, zero and positives. Pink half: leftmost bit 1, negatives. Click any pattern to jump to it.
When a result needs more bits than are available, it wraps round to a wrong value: that is . In 8-bit two's complement, 100 + 50 gives −106, because 150 does not fit.
Text#
To store text, every character is given a number by a character set. was the first widely used one: 7 bits, so 128 codes, covering English letters, digits, punctuation and invisible control codes. ‘A’ is 65, ‘a’ is 97, the digit ‘0’ is 48. Letters are in order, so ‘B’ is 66, which is how programs sort text alphabetically.
128 characters is nowhere near enough for the world's languages. gives every character in every writing system its own number, a code point, written like U+0041 (that is ‘A’ again: Unicode keeps the ASCII codes). Unicode now covers well over 100,000 characters, emoji included. To store those numbers, the web uses : characters in the ASCII range take 1 byte, others take 2, 3 or 4.
Up to 60 characters.
Characters
9
ASCII (1 byte each)
can’t store it
UTF-8
15 bytes
ASCII has only 128 codes (7 bits), so it has no code for é 汉 👋. Unicode gives every character a number, and UTF-8 stores small numbers in 1 byte and bigger ones in 2, 3 or 4 bytes.
Character by character
| Char | Code (denary) | Unicode | In ASCII? | Code in binary | UTF-8 bytes (hex) |
|---|---|---|---|---|---|
| H | 72 | U+0048 | ✓ yes | 01001000 | 48 (1) |
| i | 105 | U+0069 | ✓ yes | 01101001 | 69 (1) |
| ! | 33 | U+0021 | ✓ yes | 00100001 | 21 (1) |
| space | 32 | U+0020 | ✓ yes | 00100000 | 20 (1) |
| é | 233 | U+00E9 | ✗ no | 11101001 | C3 A9 (2) |
| space | 32 | U+0020 | ✓ yes | 00100000 | 20 (1) |
| 汉 | 27,721 | U+6C49 | ✗ no | 110110001001001 | E6 B1 89 (3) |
| space | 32 | U+0020 | ✓ yes | 00100000 | 20 (1) |
| 👋 | 128,075 | U+1F44B | ✗ no | 11111010001001011 | F0 9F 91 8B (4) |
Some emoji (skin tones, flags, families) are several code points joined together, so they show here as more than one row.
Images#
A bitmap image is a grid of , each storing a number for its colour. Two things fix the size: the (width × height in pixels) and the (bits per pixel). With n bits per pixel there are 2ⁿ possible colours: 1 bit gives black and white, 8 bits give 256 colours, 24 bits (one byte each for red, green and blue) give about 16.7 million.
Brush colour
brush = colour 0 = 0
Pixels
8 × 8 = 64
Bits per pixel
1
Size
64 bits = 8 bytes
What is actually stored, row by row
Alternate pixels are coloured so you can see where each one starts. Doubling the colour depth doubles the size; the picture only looks better if the extra colours are used. Real files also store a small header (width, height, depth) before these bits.
Sound#
Sound is a smooth, continuously changing wave: it is analogue. To store it, the computer measures it at regular moments and stores each measurement as a number. How many times per second is the ; how precisely each measurement is stored is the . Raise either and the stored sound is closer to the real one, and the file grows.
How big is real audio?
44,100 samples/s × 16 bits × 2 channels × 180 s = 254,016,000 bits
÷ 8 = 31,752,000 bytes ≈ 31.8 MB uncompressed
Video#
A video is a sequence of still images, called frames, shown quickly enough that the eye sees smooth movement: the , usually 24 to 60 frames per second. Each frame is stored like a bitmap image. Uncompressed, one second of full-HD video at 30 frames per second is 1920 × 1080 × 24 × 30 = 1,492,992,000 bits, about 187 MB, every second.
A video file holds more than frames. A such as MP4 or MKV packages several streams together: the video, one or more audio tracks (stored as in the sound section above), subtitles, and metadata such as the resolution, frame rate and length. The streams are interleaved in small chunks, so the sound for each moment arrives alongside its pictures and stays in sync during playback.
Because raw frames are so large, video is always compressed (A1.1.8), in two ways at once:
- Spatial compression (within a frame): each frame is compressed like a photo, removing detail the eye will not miss.
- (between frames): consecutive frames are usually almost identical, so only some frames are stored in full. For the frames in between, only what changed is stored, such as “this block moved 3 pixels left”. A talking head against a still background compresses enormously; fast action with lots of movement does not.
16,777,216 possible colours
These are uncompressed sizes. Formats like JPEG, MP3 and MP4 compress the data, so real files are usually much smaller.
The size
Working
- size = width × height × colour depth
- = 640 × 480 × 24
- = 7,372,800 bits
- ÷ 8 = 921,600 bytes
- ÷ 1000 for each step up (kB, MB, GB) = 921.6 kB
- or ÷ 1024 for each step up (KiB, MiB, GiB) = 900 KiB
Bytes
921,600
Decimal units (1 kB = 1000 B)
921.6 kB
Binary units (1 KiB = 1024 B)
900 KiB
Why the encoding matters for storing and finding data#
The way data is encoded decides how much space it takes, how quickly it can be found again, and whether it survives being stored or sent:
- Fixed width makes data quick to find. If every item takes the same number of bits (every integer 32 bits, every pixel 24 bits), the computer can jump straight to item number n by working out n × width, instead of reading everything before it. Variable-width encodings such as UTF-8 save space but must be read from the start.
- The program must know the format. Bits carry no meaning on their own (Figure 1). A file therefore starts with , a header saying what kind of data follows and how it is laid out (an image's width, height and colour depth).
- Standard formats mean data can be shared. Because everyone agrees on ASCII, UTF-8, PNG or MP3, a file written on one computer can be read on any other.
- Extra bits can catch errors. Bits can be flipped by electrical noise or a damaged disc. A is one extra bit chosen so that the total number of 1s is even. For the 7 bits
1101011, which contain 5 ones, the parity bit is 1, giving11010111. If any one bit later flips, the count of 1s becomes odd and the error is detected (though not where it is).
Check yourself
Two's complement, text, media and parity
Quick questions, made fresh every time and marked here. Do a few until they feel easy.
Exam practice
Paper 1-style questions
8 questions · 23 marks
Write your answer as you would in the exam, then show the mark points and tick each one your answer made. These are our own questions in the style of the exam, not past-paper questions.
1.Calculate the 8-bit two's complement representation of -52. Show your working.
[2]Calculate: Work out the number, showing the working.
2.State the range of whole numbers that can be stored in 8-bit two's complement.
[1]State: Give a short answer, no explanation needed.
3.Explain why web pages are usually stored in UTF-8 rather than ASCII.
[3]Explain: Give reasons: say what happens AND why, or how one thing causes another.
4.Calculate the uncompressed size, in bytes, of a 800 × 600 pixel image with a colour depth of 16 bits.
[2]Calculate: Work out the number, showing the working.
5.Describe how a sound is converted into digital form.
[4]Describe: A detailed account: say what happens, step by step if it is a process.
6.Explain how temporal compression reduces the size of a video file.
[3]Explain: Give reasons: say what happens AND why, or how one thing causes another.
7.Outline how an even parity bit is used to detect an error in stored or transmitted data.
[2]Outline: A brief account: the main points, without much detail.
8.A photographer’s website shows photos at a high resolution and a colour depth of 24 bits. Discuss the effects of reducing the resolution and the colour depth of the photos on the website.
[6]Discuss: Look at the question from more than one side, weigh the points against each other, and come to a conclusion.
Past papers
Old exam questions on this topic
From HL Paper 1, May 2014 to November 2025. These papers were set on the previous syllabus, so the wording may differ from today's exam, but the topic is the same. Find the questions and markschemes in your school's past-paper pack.
| Paper | Question | Marks | About |
|---|---|---|---|
| May 2023 TZ1 | 3 | 2 | Why Unicode |
| November 2022 | 5 | 2 | RGB in binary; colours per pixel |
| November 2019 | 3(b) | 2 | Bits per colour, colours per pixel |
| May 2018 | 3 | 2 | Colours from two hex digits |
| November 2018 | 8(c) | 4 | One byte: hex, how many values, why not enough for Chinese |
| May 2014 | 7 | 2 | How a colour is represented |
In a nutshell
- The same bits can mean different things: a number, a character, a colour. The program decides how to read them.
- Unsigned integers use plain binary (n bits: 0 to 2ⁿ − 1). Two's complement makes the leftmost bit negative (n bits: −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1).
- To make a negative number in two's complement: write the positive version, flip every bit, add 1.
- Text: each character has a code. ASCII has 128 (7 bits). Unicode covers every writing system; UTF-8 stores it in 1 to 4 bytes.
- Images: size = width × height × colour depth (bits). n bits per pixel give 2ⁿ colours.
- Sound: size = sample rate × bit depth × channels × seconds. Video: size = one frame × frames per second × seconds.
- A video file is a container (MP4, MKV) holding frames, audio, subtitles and metadata in sync. It is compressed within frames (spatial) and between frames (temporal).
- Encoding affects storage and retrieval: fixed widths are quick to search, metadata says how to read the bits, standards allow sharing, and parity bits detect errors.
- Divide bits by 8 for bytes, then by 1000s (kB, MB) or 1024s (KiB, MiB) as the question asks.
