Leftmost bit: most significant bit (MSB). Rightmost: least significant bit (LSB).
Each extra bit doubles the patterns: 8 bits give 256 (0 to 255).
Leading zeros change nothing: 11010 = 0001 1010.
128
64
32
16
8
4
2
1
0
1
1
0
1
0
0
1
Calculate
?Convert the binary number 1011 0110 to denary.
Your answer
?Convert the denary number 200 to 8-bit binary.
Data representation · number bases
Hexadecimal
Hexadecimal (base 16) has sixteen digits: 0–9, then A–F for 10–15.
One hex digit is exactly 4 bits (a nibble), as 4 bits give 16 patterns.
Binary to hex: split into nibbles from the right: 1101 0111 → D7.
Hex to binary: each digit becomes 4 bits: 3F → 0011 1111.
Hex to denary: 8C = 8 × 16 + 12 = 140.
Denary to hex: 200 ÷ 16 = 12 r 8, so C8.
Your answer
?Convert the binary number 1011 1110 to hexadecimal.
Calculate
?Convert the hexadecimal number A7 to denary.
Data representation · number bases
Why use hex?
Computers never store hex. It is a shorthand for binary for humans.
Hex is much shorter: 8 bits become 2 hex digits.
It is easier to read, remember and copy without mistakes than long strings of 0s and 1s.
Converting hex to binary is quicker than converting denary to binary, because each digit maps to 4 bits.
Uses: colour codes in web pages, MAC addresses, memory addresses and error codes.
Mission check
?Why is a web colour such as #FF8C00 written with letters and numbers?
#FF8C00 is hexadecimal. Each pair of hex digits is one byte for red, green and blue: FF = 1111 1111 = 255, 8C = 1000 1100 = 140, 00 = 0. Six hex digits are far easier for people to read and copy than the 24 bits the computer actually stores.
Mission 2
How can a computer multiply by 8 without doing any multiplying?
Make a guess: How can a computer multiply by 8 without doing any multiplying?
Data representation · binary arithmetic
Adding in binary
Add column by column from the right, carrying like denary addition.
?Add these three binary numbers: 0010 0101 + 0001 0011 + 0100 0110. Give the 8-bit answer.
Data representation · binary arithmetic
Binary shifts
Binary columns double in value from right to left.
A binary shift slides every bit left or right. Bits pushed off the end are lost; gaps fill with 0.
Left 1 place: × 2. Right 1 place: ÷ 2, remainder lost. Use: fast × or ÷ by 2, 4, 8.
0000 1101 (13) shifted left 1 → 26; right 1 → 6.
This is a logical shift.
Your answer
?Shift 0001 0110 three places to the left. Give the 8-bit result.
Calculate
?Shift 0110 1101 (109) two places to the right. What is the result in denary?
Quick check
?1110 0000 (224) is shifted 2 places left in an 8-bit register. What is the result?
Mission check
?How can a computer multiply a number by 8 without doing any multiplying?
Shifting every bit one place left doubles a binary number, because each column is worth twice the one to its right. Three places left doubles it three times: × 8. So 0001 0110 (22) becomes 1011 0000 (176), as long as no 1s fall off the end.
Mission 3
How does a computer store the letter A if it can only store numbers?
Make a guess: How does a computer store the letter A if it can only store numbers?
Data representation · characters
Characters as codes
Each character (letter, digit, symbol, space) is stored as a binary number: its character code.
A character set is the agreed list of characters a computer can use, each with its own code.
Using a standard character set means text keeps its meaning when it moves between programs and devices.
Typing A sends A's code; the screen looks up the code to draw the A.
Data representation · characters
ASCII
ASCII (American Standard Code for Information Interchange) uses 7 bits per character.
7 bits give 2⁷ = 128 codes (0 to 127): English letters, digits, punctuation, space and control codes such as Enter.
More bits per character means more possible characters.
Data representation · characters
Codes run in order
Codes are grouped and run in sequence: A = 65, B = 66, C = 67 … Z = 90.
Lower case runs on from a = 97; the digits from '0' = 48.
Know one code and you can work out its neighbours: 'C' = 65 + 2 = 67.
The character '7' has code 55. It is not the number 7.
Calculate
?In ASCII, 'A' has the code 65. What is the code for 'H'?
Your answer
?In ASCII, 'a' is 0110 0001. What is the binary code for 'd'?
Your answer
?In ASCII, 'A' is 65. Which word do the codes 66 69 68 spell? Type it in capitals.
Data representation · characters
Unicode
ASCII's 128 codes cannot cover other alphabets. Unicode aims to code every writing system, plus symbols and emoji: about 160,000 characters so far.
Unicode uses more bits per character than ASCII, so text takes more storage.
Its first 128 codes are the same as ASCII: 'A' is 65 in both.
Quick check
?A messaging app must show Arabic, Chinese and emoji. Which character set should it use?
Mission check
?How does a computer store the letter A when it can only store numbers?
Every character has an agreed number in a character set. In ASCII, A is 65, stored as the binary pattern 100 0001. Because every device uses the same standard, the 65 sent by one phone is drawn as A on another.
Mission 4
Double a photo's width and height: how much bigger is the file?
Make a guess: Double a photo's width and height: how much bigger is the file?
Data representation · images and file sizes
Pictures made of dots
A pixel (picture element) is a single point in an image.
A bitmap is a grid of pixels. Each pixel's colour is stored as a binary code.
Image size is the number of pixels, written width x height, e.g. 800 x 600.
More pixels: more detail, but more data to store.
Data representation · images and file sizes
Colour depth
Colour depth is the number of bits used to store each pixel's colour.
n bits give 2ⁿ colours: 1 bit gives 2, 8 bits 256, 24 bits about 16.7 million.
In a 1-bit image, 1 could mean black and 0 white: each row is a bit pattern, and a bit pattern can be drawn back as pixels.
Higher colour depth: more colours and better quality, but a bigger file.
Your answer
?This row comes from a 1-bit image where black = 1 and white = 0. Reading left to right, write the bit pattern for the row.
Data representation · images and file sizes
Working out file size
File size in bits = width x height x colour depth. Divide by 8 for bytes.
Example: 800 x 600 pixels at 24 bits is 800 x 600 x 24 = 11,520,000 bits = 1,440,000 bytes.
No calculator? Write the whole expression, then cancel before multiplying.
Calculate
?An image is 200 x 100 pixels with a colour depth of 8 bits. What is its file size?
bytes
Data representation · images and file sizes
Units of data
A bit (b) is a single 0 or 1. A byte (B) is 8 bits.
Unit
Symbol
Size
kilobyte
kB
1,000 bytes
megabyte
MB
1,000 kB
gigabyte
GB
1,000 MB
terabyte
TB
1,000 GB
Each step up is x 1,000, so divide by 1,000 to go up one unit.
You may see 1,024 used elsewhere, but AQA uses 1,000.
Calculate
?A photo file is 2,048,000 bytes. What is its size in kilobytes?
kB
Calculate
?A camera saves every photo as exactly 4 MB. How many photos fit on an empty 1 GB memory card?
photos
Mission check
?Double a photo's width and height: how much bigger is the file?
File size = width x height x colour depth. Doubling the width and the height gives 2 x 2 = 4 times as many pixels, each with the same colour depth, so the file needs 4 times as many bits.
Mission 5
How can a list of numbers turn into a song?
Make a guess: How can a list of numbers turn into a song?
Data representation · sound
Sound is analogue
Sound is a wave that changes smoothly and continuously: it is analogue.
A computer can only store binary, so the sound must be converted to digital form.
To do this, the wave's height (amplitude) is measured at regular moments. Each measurement is a sample: the amplitude at a point in time.
Each sample is stored as a binary number.
Data representation · sound
Sample rate and bits per sample
Sampling rate (or sample rate): samples taken per second, in hertz (Hz). Music is often sampled 44,100 times a second.
Sample resolution (or bit depth): bits used to store each sample.
Raise either one: the sound is closer to the original, but the file is bigger.
Quick check
?A recording app changes its sample rate from 22,050 Hz to 44,100 Hz. Nothing else changes. What happens?
Data representation · sound
Working out sound file size
File size in bits = sampling rate x sample resolution x length in seconds.
Divide by 8 to get bytes.
Example: 1 second at 44,100 Hz and 16 bits is 44,100 x 16 = 705,600 bits.
Without a calculator, write the whole expression first, then cancel before you multiply.
These questions assume one channel (mono) unless they say otherwise.
Calculate
?A voice memo is sampled at 8,000 Hz with a sample resolution of 8 bits. It lasts 10 seconds. What is its file size?
bytes
Calculate
?A sound file is 96,000 bytes. It was sampled at 8,000 Hz with 8 bits per sample. How long is the recording?
seconds
Calculate
?A clip is sampled at 32,000 Hz with a sample resolution of 16 bits. It lasts 64 seconds. What is its file size in kilobytes?
kB
Quick check
?To save space, an app stores samples with 8 bits instead of 16. What is the effect?
Mission check
?How can a list of numbers turn into a song?
The sound wave is sampled: its amplitude is measured thousands of times a second and each sample is stored as a binary number. Played back in order at the same rate, the numbers rebuild the shape of the wave, so a higher sample rate and more bits per sample give a closer copy and a bigger file.
Mission 6
How can a file shrink but still open exactly as before?
Make a guess: How can a file shrink but still open exactly as before?
Data representation · compression
Why compress?
Compression makes a file smaller, so it uses fewer bits.
Smaller files need less storage space.
They take less time to send or download and use less bandwidth.
Common cases: streaming video and music, web pages, email attachments, photos on a phone.
There are different ways to compress data. Two you need are run length encoding and Huffman coding.
Data representation · compression
Squeezing out repetition
Data often repeats: a row of 6 white pixels, then 3 black, then 4 white.
Instead of storing all 13 pixels, store each run as a count and a value: 6 W, 3 B, 4 W.
The original can be rebuilt exactly, bit for bit. Compression that loses nothing is lossless.
The more repetition there is, the more the file shrinks.
Quick check
?Two images are the same size. One is a logo with large areas of flat colour. The other is TV static, where neighbouring pixels are random colours. Which shrinks more using repetition, and why?
Data representation · compression
Run length encoding
Run length encoding (RLE) replaces each run of repeated data with a pair: how many times it repeats, then the value.
RLE is lossless. With little repetition it can make the data bigger, as every single value gains a count.
Your answer
?Encode this row of a 1-bit image using RLE pairs (count, then value): 1111000000001100
Mission check
?How can a file shrink but still open exactly as before?
Data usually contains repetition. Lossless compression stores repeated patterns more efficiently, for example as a count and a value, so the file uses fewer bits and the original can be rebuilt exactly.
Mission 7
Morse code: why is E a single dot?
Make a guess: Morse code: why is E a single dot?
Data representation · Huffman coding
Codes of different lengths
7-bit ASCII gives every character 7 bits, however often it is used.
Huffman coding gives frequent characters short codes and rare characters longer codes.
So the whole piece of data needs fewer bits, and nothing is lost: the original can be rebuilt exactly.
The codes come from a Huffman tree, built from how often each character appears in the data.
Data representation · Huffman coding
Reading a Huffman tree
Characters sit at the ends of the branches. Each branch is labelled 0 or 1: on this tree, left is 0 and right is 1.
A character's code is the list of branch labels from the top of the tree down to it.
Frequent characters sit near the top, so they get short codes.
No code is the start of another, so a string of bits decodes one way only.
Your answer
?Use the Huffman tree. What is the code for T?
Your answer
?Use the same tree to decode this bit string: 1110010110
Data representation · Huffman coding
Building a Huffman tree
List the characters and their frequencies, lowest first.
Join the two lowest under a new node holding their total.
Put it back in order and repeat until one node is left: the root.
Our tree: S 1 + N 1 = 2, then T 2 + 2 = 4, then A 3 + 4 = 7, then E 7 + 7 = 14.
Frequent characters join last, so they sit nearest the root.
Data representation · Huffman coding
Counting the bits
Huffman bits: add up frequency x code length for each character.
Uncompressed bits in 7-bit ASCII: number of characters x 7.
Bits saved = ASCII bits − Huffman bits.
Example: NEAT is 1111 0 10 110 = 4 + 1 + 2 + 3 = 10 bits. In 7-bit ASCII it is 4 x 7 = 28 bits, so 18 bits are saved.
Calculate
?The tree was built from a message of 14 characters: E x 7, A x 3, T x 2, S x 1, N x 1. How many bits does the whole message need using the Huffman codes?
bits
Calculate
?The same 14-character message is stored in 7-bit ASCII instead. How many bits does Huffman coding save?
bits
Mission check
?Morse code: why is E a single dot?
E is the most common letter in English, so Morse gave it the shortest code, a single dot. Huffman coding uses the same idea: frequent characters get short codes, so the whole message needs fewer bits.
Recap
Big ideas
Computers store all data and instructions as binary. Binary place values double: 1, 2, 4 … 128, so 8 bits hold 0 to 255.
One hex digit = 4 bits (a nibble). Hex digits A–F mean 10–15.
Convert hex to denary with ×16: 8C = 8 × 16 + 12 = 140.
Hex is a shorthand for humans: shorter, easier to read and fewer copying mistakes.
Binary addition: 1 + 1 = 10 and 1 + 1 + 1 = 11, so write the right digit and carry the left.
Shift left n places: × 2ⁿ. Shift right n places: ÷ 2ⁿ, rounded down. Bits pushed off the end are lost.
A character set is an agreed list of characters with a binary code for each. Codes run in order, so B is one more than A.
ASCII uses 7 bits: 128 characters, enough for English.
Unicode uses more bits per character to cover far more characters, including other alphabets and emoji; its first 128 codes match ASCII.
A bitmap is a grid of pixels; colour depth is the bits per pixel, and n bits give 2ⁿ colours.
File size (bits) = width x height x colour depth; divide by 8 for bytes.
Each unit up (kB, MB, GB, TB) is x 1,000.
A sample is the amplitude of the wave at one point in time, stored in binary.
Sampling rate = samples per second (Hz); sample resolution = bits per sample. Both raise quality and file size.
File size (bits) = sample rate x bits per sample x seconds.
Compression makes files smaller: less storage, faster transfer, less bandwidth.
Lossless compression rebuilds the original exactly by storing repetition efficiently.
RLE stores each run as a count and a value: 0000011100000011 → 5 0 3 1 6 0 2 1.
Huffman coding gives frequent characters short codes and rare ones longer codes; it is lossless.
Build the tree by repeatedly joining the two lowest frequencies; read a code by following the 0 and 1 branch labels from the root down.
Huffman bits = sum of frequency x code length; ASCII bits = characters x 7; saved = the difference.
🏆
Mini-lesson complete!
⭐⭐⭐
You've worked through Fundamentals of data representation for AQA GCSE Computer Science (8525). 🎉
Mission 1Web colours look like #FF8C00. Why letters and numbers?
Mission 2How can a computer multiply by 8 without doing any multiplying?
Mission 3How does a computer store the letter A if it can only store numbers?
Mission 4Double a photo's width and height: how much bigger is the file?
Mission 5How can a list of numbers turn into a song?
Mission 6How can a file shrink but still open exactly as before?