← All tools

Data Representation – Part 3

How computers store characters, images and sound, how compression shrinks files — and how to calculate file sizes the OCR way. Diagrams, worked examples, a file-size calculator and a timed 20-question quiz at the end.

LO: How are images and data stored?  ·  Spec: OCR GCSE Computer Science (J277), Paper 1 — data representation.

Key Meanings

The key terms from this lesson, grouped by topic.

Characters

Character set
A defined collection of characters a computer recognises, each with its own binary code.
ASCII
7 bits per character = 128 characters (English letters, digits, symbols). Usually stored in an 8-bit byte.
Extended ASCII
8 bits per character = 256 characters — adds accented letters and extra symbols.
Unicode
16 bits or more per character — covers almost every language, plus symbols and emoji.

Images

Pixel
The smallest single dot of a bitmap image. Each pixel is stored as a binary code.
Colour depth
The number of bits used to store each pixel. n bits gives 2n colours.
Resolution
The number of pixels in an image (width × height). More pixels = more detail.
DPI
Dots per inch — how many dots are packed into each inch when printed or displayed.
Metadata
Data about the file (type, width, height, colour depth…) so the computer can rebuild the image.

Sound

Analogue
A smooth, continuous signal, like a real sound wave.
Digital
Sound stored as a list of binary numbers, measured at set moments.
Sample rate
How many samples are taken each second, measured in hertz (Hz). CD quality = 44,100 Hz.
Sample interval
The gap in time between one sample and the next.
Bit depth (sample size)
The number of bits used for each sample.
Bit rate
The number of bits used for each second of sound.

Compression

Compression
Making a file smaller so it uses less storage and transfers faster.
Lossy
Permanently removes some data. Much smaller files, but the original can’t be restored.
Lossless
Makes the file smaller without losing any data — the original is rebuilt exactly.

File Sizes & Units

Bit → byte
8 bits = 1 byte. A nibble is 4 bits.
Kilobyte (KB)
1,000 bytes (OCR’s convention).
MB / GB / TB
Each is 1,000 times bigger than the one before.
File size
How much storage a file needs — worked out in bits, then converted.

1. Characters

Every key you press is turned into a binary number the computer can store.

A character set is the collection of characters a computer can recognise, with a unique binary code for each one. The codes are in order, so once you know that A = 65 you can work out B = 66, C = 67 and so on.

ASCII codes

CharacterDenaryBinary (8-bit)
A6501000001
B6601000010
C6701000011
a9701100001
04800110000
+4300101011
space3200100000
Standard ASCII only needs 7 bits — a 0 is added at the front to fill a whole byte.

How many characters can each set hold?

ASCII (7-bit)128
Extended ASCII (8-bit)256
Unicode (16-bit)65,536+

Bars not to scale — Unicode really is that much bigger.

A keyboard
Different languages need different keys — Unicode has room for them all.

Comparing the character sets

SetBits per characterCharactersUsed for
ASCII727 = 128English letters, digits, punctuation, control codes
Extended ASCII828 = 256Adds accented letters (é, ñ) and extra symbols — useful for languages like French
Unicode16 or more (up to 32)65,536+Almost every language in the world, symbols and emoji — ideal for keyboards worldwide

The trade-off: more bits per character means a bigger text file.

2. Images

A bitmap image is a grid of tiny squares — each one has a binary colour code.

Bitmap images are made of pixels. In the simplest case, 1 = black and 0 = white. Here is an 8 × 8 image stored in just 1 bit per pixel — the binary code on the right is exactly what the computer stores:

1-bit image (64 pixels)


          
Image size = 8 × 8 × 1 bit = 64 bits = 8 bytes.

Colour depth

Colour depth is the number of bits for each pixel. More bits means more possible colours: number of colours = 2bits.

Colour depthWorkingColours
1-bit212
2-bit224
4-bit2416
8-bit28256
16-bit21665,536
24-bit22416,777,216
The same flower photo shown at 16-bit, 8-bit, 4-bit and 1-bit colour depth
The same photo at 16-bit, 8-bit, 4-bit and 1-bit. With fewer bits there are fewer colours, so smooth changes turn into blocky bands — this is why a 4-bit image might not look good.

Resolution, DPI and metadata

  • Resolution is the number of pixels in the image (width × height), e.g. 1920 × 1080. More pixels = more detail, but a bigger file.
  • DPI (dots per inch) is how closely packed the dots are when the image is printed or shown. Higher DPI = sharper picture.
  • Metadata is data about the image stored in the file — file type, size, height, width, colour depth — so the computer can rebuild the picture from the binary.

Right-click any picture → Properties → Details to see its metadata (width, height, bit depth, resolution…).

3. Sound

Real sound is analogue. To store it, the computer measures it over and over — this is called sampling.

An original sound wave, an analogue sound wave and a digital sound wave
An analogue wave is smooth; the digital version is made of steps.

Low sample rate (few samples)

Big steps — a poor copy of the wave.

High sample rate (many samples)

Small steps — much closer to the original, but more data to store.

Factors that affect quality and file size

  • Sample rate — samples per second, in hertz (Hz). 44,100 Hz (44.1 kHz) is CD quality. The sample interval is the tiny gap between samples (a higher rate means a shorter interval).
  • Bit depth (sample size) — bits used for each sample. 16-bit is CD quality. More bits = each sample is measured more precisely.
  • Bit rate — bits used per second: sample rate × bit depth (× 2 for stereo).
  • Duration — the longer the recording, the bigger the file.

Increasing the sample rate or the bit depth makes the sound closer to the original recording — but the file gets bigger.

4. Compression

Making files smaller — for storage, loading times and sending attachments.

Compression has three big benefits: files take less storage space, they load and stream faster over the internet, and they can be sent as attachments quicker. There are two types:

LossyLossless
How it worksPermanently removes data the user is unlikely to noticeRewrites the data more efficiently (e.g. finding repeats) — no data is lost
QualityDrops, depending on how much is compressed. The original cannot be restoredIdentical to the original when decompressed
File sizeMuch smallerOnly a small reduction — still much bigger than lossy
Best forPhotos, music, video, websitesText, program code, documents, anything that must be perfect
ExamplesJPEG, MP3, MP4ZIP, PNG, FLAC
The same dog photo: original 824 KB, 50% lossy 76 KB, 80% lossy 38 KB
Same photo, three files: 824 KB → 76 KB → 38 KB. The more lossy compression, the smaller the file — and the more quality is lost.

Why lossy for songs on a phone? Smaller files mean more songs fit in limited storage, and they download or stream quicker using less data. Why lossless for text? Lose one character and the document or program is broken.

5. Calculating File Sizes

The three OCR formulas — always calculate in bits first, then convert.

The units ladder

bit0 or 1
×4
nibble4 bits
×2
byte8 bits
×1000
KB
×1000
MB
×1000
GB
×1000
TB
×1000
PB

bits ÷ 8 = bytes  →  bytes ÷ 1000 = KB  →  KB ÷ 1000 = MB

Formula 1 — Text

File size (bits) = bits per character × number of characters

Worked example — text

A document has 2,000 characters stored in 7-bit ASCII. How big is it?

  1. 7 × 2,000 = 14,000 bits
  2. 14,000 ÷ 8 = 1,750 bytes
  3. 1,750 ÷ 1,000 = 1.75 KB
Answer: 14,000 bits (1.75 KB)

Formula 2 — Image (the one missing from the slides)

File size (bits) = colour depth × image width × image heightwidth and height are measured in pixels — width × height = the resolution = the number of pixels

Worked example 1 — small image

An image is 800 pixels wide and 600 pixels high with a colour depth of 8 bits.

  1. Pixels: 800 × 600 = 480,000
  2. Bits: 480,000 × 8 = 3,840,000 bits
  3. Bytes: 3,840,000 ÷ 8 = 480,000 bytes
  4. KB: 480,000 ÷ 1,000 = 480 KB
Answer: 3,840,000 bits (480 KB)

Worked example 2 — full HD photo

An image is 1920 × 1080 pixels with a 24-bit colour depth.

  1. Pixels: 1,920 × 1,080 = 2,073,600
  2. Bits: 2,073,600 × 24 = 49,766,400 bits
  3. Bytes: 49,766,400 ÷ 8 = 6,220,800 bytes
  4. MB: 6,220,800 ÷ 1,000,000 = 6.22 MB
Answer: 49,766,400 bits (about 6.22 MB)

Formula 3 — Sound

File size (bits) = sample rate (Hz) × bit depth × duration (seconds)If a question says stereo, there are 2 channels — check whether it expects you to double the answer.

Worked example — sound

A 10-second recording uses a sample rate of 44,100 Hz and a bit depth of 16.

  1. Bits: 44,100 × 16 × 10 = 7,056,000 bits
  2. Bytes: 7,056,000 ÷ 8 = 882,000 bytes
  3. KB: 882,000 ÷ 1,000 = 882 KB
Answer: 7,056,000 bits (882 KB)

Exam tips: (1) Write the formula first. (2) Do the multiplying in bits — only divide by 8 at the end if the question asks for bytes. (3) Check the units asked for (bits, bytes, KB or MB). (4) If the question gives the sample rate in kHz, convert it: 44.1 kHz = 44,100 Hz.

Try it — File Size Calculator

Type in your own numbers and the calculator shows every step. Use it to check your working, not to skip it!

Test Yourself — 20 Question Quiz

Multiple choice, true/false, fill in the blanks, drag-and-drop, matching, ordering and sorting — plus calculations. The timer starts when you press Start. Have a calculator and some paper ready!