Data Representation
Binary, denary and hexadecimal number systems, two's complement, logical shifts, text, sound and image representation, storage units and compression. Everything in topic 1 of the 0478 / 2210 syllabus, with worked examples.
Computers only understand one thing: electrical signals that are either ON or OFF. Everything else, every number, letter, photo, song and video, has to be turned into a pattern of these two states before a computer can store or process it. This chapter is about exactly how that conversion works. Master it, because almost every later topic builds on these ideas.
Why Do Computers Use Binary?
Inside every computer are millions of tiny electronic switches called transistors. A transistor can only be in one of two states: it is either letting current through (ON) or it is not (OFF). We represent these two states with the digits 1 (ON) and 0 (OFF).
Because hardware naturally has two states, the simplest and most reliable way to store and move data is to use a number system with just two digits. That system is binary. Any form of data, whether it is a number, a letter, an image or a sound, must first be converted into binary so the computer can process it.
Two more terms you must know: data is processed using logic gates (covered fully in Chapter 10) and is held inside the CPU in tiny stores called registers (Chapter 3).
The Three Number Systems
The syllabus expects you to know three number systems and to convert between them. The key idea behind any system is its base: the number of different digits it uses.
| System | Base | Digits used | Where it is used |
|---|---|---|---|
| Binary | 2 | 0, 1 | Inside the computer, at the hardware level |
| Denary (decimal) | 10 | 0 to 9 | Everyday human counting |
| Hexadecimal | 16 | 0 to 9, then A to F | A short, human-friendly way to write binary |
Key vocabulary
Bit
A single binary digit, either 0 or 1. The smallest unit of data.
Nibble
A group of 4 bits. Exactly one hexadecimal digit.
Byte
A group of 8 bits. The standard unit for measuring storage.
Converting Between Binary and Denary
An 8-bit binary number has a fixed set of place values, each one double the value to its right, starting from 1 on the far right:
Tap any bit to flip it on or off. Watch the denary total update live.
Binary to denary
Wherever there is a 1, add that column's place value. Ignore the columns with a 0.
Denary to binary (repeated division by 2)
Divide the number by 2 over and over, writing down the remainder each time. Then read the remainders from bottom to top.
Reading the remainders from bottom to top gives 101101. Padded to 8 bits:
45 = 00101101Hexadecimal
Long strings of binary are hard for humans to read and easy to copy wrongly. Hexadecimal solves this: one hex digit represents exactly 4 binary bits, so hex is four times shorter than binary while still mapping cleanly onto it.
Why hexadecimal is useful
- It is much shorter than binary, so it is easier to read and write
- It is less error-prone when humans copy values by hand
- It converts to and from binary very easily (4 bits per digit)
You will meet hex again in MAC addresses, IP addresses (IPv6), colour codes in HTML, and memory addresses.
Why do programmers use hexadecimal?
Programmers in particular reach for hexadecimal because a single hex digit is equivalent to exactly 4 bits of binary. Compressing every 4 bits into one symbol makes long binary values:
- Easier to read, because the value is a quarter of the length
- Easier to understand, since each digit maps cleanly to one nibble
- Easier to debug, as mistakes are far quicker to spot in a short hex string than in a long row of 1s and 0s
Seeing it at scale: 32 bits
The benefit becomes obvious with longer values. Here is a 32-bit binary number split into its four bytes (eight nibbles), with the matching hexadecimal underneath. Notice how 32 digits of binary collapse into just 8 digits of hex.
11011001101001111111000011010110 = D9A7F0D6
Binary to hexadecimal
Split the binary into groups of 4 bits, working from the right. Convert each nibble to its hex digit.
Press play to watch an 8-bit number split into two nibbles, each becoming one hex digit.
The 16 hex values to memorise
It pays to know these by heart. Each row shows one hex digit, the nibble it stands for, and its denary value.
| Hex | Binary | Denary | Hex | Binary | Denary |
|---|---|---|---|---|---|
0 | 0000 | 0 | 8 | 1000 | 8 |
1 | 0001 | 1 | 9 | 1001 | 9 |
2 | 0010 | 2 | A | 1010 | 10 |
3 | 0011 | 3 | B | 1011 | 11 |
4 | 0100 | 4 | C | 1100 | 12 |
5 | 0101 | 5 | D | 1101 | 13 |
6 | 0110 | 6 | E | 1110 | 14 |
7 | 0111 | 7 | F | 1111 | 15 |
Hexadecimal to binary
Reverse the process: turn each hex digit into its 4-bit binary nibble and join them together.
Hexadecimal to denary and back
To go from hex to denary, multiply each digit by its place value (powers of 16: ..., 256, 16, 1). To go from denary to hex, the easiest route is usually denary to binary, then binary to hex.
Binary Addition and Overflow
Adding binary works just like adding denary, except you carry whenever a column total reaches 2 (not 10). The four rules are:
| Sum | Result | Carry |
|---|---|---|
0 + 0 | 0 | no carry |
0 + 1 | 1 | no carry |
1 + 1 | 0 | carry 1 |
1 + 1 + 1 | 1 | carry 1 |
Overflow
An 8-bit register can only hold values from 0 to 255 (that is 11111111). If an addition produces a result larger than 255, there is no room for the extra bit. This is called an overflow error: a 9th bit is generated but cannot be stored, so it is lost and the stored answer is wrong.
The correct answer is 288, but 8 bits can only store up to 255. The extra leading bit is lost, so an overflow error has occurred.
Logical Binary Shifts
A logical shift moves all the bits in a register left or right by a given number of places. Empty positions are filled with zeros, and any bits pushed off the end are lost permanently.
| Left shift | Right shift | |
|---|---|---|
| Bits move | Left by n places | Right by n places |
| Zeros fill | From the right | From the left |
| Effect | Multiplies by 2n | Divides by 2n |
Shifting left by 2 multiplies by 2² = 4, and indeed 6 × 4 = 24.
6 shifted left 2 = 24Shifting right by 3 divides by 2³ = 8, and 24 ÷ 8 = 3.
24 shifted right 3 = 3Two's Complement (Negative Numbers)
So far every binary number has been positive. To store negative numbers in 8 bits, we use two's complement. The trick: the most significant bit (the leftmost, normally worth 128) is given a negative place value of −128.
Converting a positive number to negative
Three steps: write the positive number in 8-bit binary, flip every bit (this is called the one's complement), then add 1.
Play to watch a positive number become negative: write it, flip the bits, then add 1.
Reading a two's complement number
Add up the place values as normal, but remember the leftmost column is worth −128.
Representing Text: ASCII and Unicode
Computers store text by giving every character a unique number, called a character code. A list of characters and their codes is a character set.
ASCII
- Uses 7 bits per character, giving 128 different characters (codes 0 to 127)
- Extended ASCII uses 8 bits, giving 256 characters
- Covers the English alphabet, digits, punctuation and control characters
- Useful codes to know:
'A'= 65,'a'= 97,'0'= 48
Unicode
- Uses more bits per character than ASCII
- Can represent over 100,000 characters
- Supports the alphabets of all world languages, plus symbols and emojis
- Is backward compatible with ASCII (the first 128 codes are identical)
Representing Sound
Sound in the real world is an analogue wave, a smooth continuous signal. Computers can only store discrete binary numbers, so the wave must be converted. This is done by sampling: measuring the height (amplitude) of the wave at regular intervals and storing each measurement as a binary number.
| Term | Definition | Effect of increasing it |
|---|---|---|
| Sample rate | The number of samples taken per second, measured in hertz (Hz) | More accurate recording, but a larger file |
| Sample resolution | The number of bits used to store each sample | More precise amplitude, but a larger file |
Representing Images
A digital image (a bitmap) is made of a grid of tiny squares called pixels. The colour of each pixel is stored as a binary number.
| Term | Definition | Effect of increasing it |
|---|---|---|
| Resolution | The total number of pixels, written as width × height | Higher quality, sharper image, larger file |
| Colour depth | The number of bits used to represent each pixel's colour | More possible colours, larger file |
Measuring Data Storage
Data size is measured in bytes, and each larger unit is 1024 times the one before it (not 1000). These are the formal "binary" units the syllabus requires.
| Unit | Equals |
|---|---|
| 1 nibble | 4 bits |
| 1 byte | 8 bits |
| 1 kibibyte (KiB) | 1024 bytes |
| 1 mebibyte (MiB) | 1024 KiB |
| 1 gibibyte (GiB) | 1024 MiB |
| 1 tebibyte (TiB) | 1024 GiB |
| 1 pebibyte (PiB) | 1024 TiB |
| 1 exbibyte (EiB) | 1024 PiB |
Calculating File Sizes
These calculations come up almost every year. Learn the two formulas and always show your working.
Image file size
Sound file size
Compression
Compression reduces the size of a file. Smaller files need less storage space, use less bandwidth, and transfer faster across a network. There are two types.
Lossless
No data is permanently removed. The original file can be reconstructed exactly. Used for text and PNG images. Example method: run length encoding (RLE).
Lossy
Some data is permanently removed to shrink the file further. The original cannot be fully recovered. Used for MP3 audio and JPEG images.
Run length encoding (RLE)
RLE is a lossless method that replaces runs of repeated values with a single value plus a count. For example, a row of pixels WWWWWWBBB becomes 6W 3B, which takes far less space while losing nothing.
Exam Practice
Try each question before reading the answer. These mirror the style and mark allocations of the real paper.
201 = 128 + 64 + 8 + 1, so the columns 128, 64, 8 and 1 each get a 1.
11001001Split into nibbles from the right: 1011 and 0101. 1011 = 11 = B, and 0101 = 5.
B500010100 is 20. Shifting left 2 places gives 01010000, which is 80. The shift multiplied the value by 2² = 4.
01010000 (80), value multiplied by 4+68 = 01000100. Flip the bits: 10111011. Add 1: 10111100.
-68 = 10111100Lossless compression reduces file size without permanently removing any data, so the original can be reconstructed exactly. It is used for text files and PNG images. Lossy compression reduces file size by permanently removing some data, so the original cannot be fully recovered. It is used for MP3 audio and JPEG images.
