Everything is numbers: text, pictures and sound
Letters, colours and music all become numbers inside a computer. Paint pixels and see the ones and zeros behind a picture.
We just learned that a computer only holds bits, and bits make numbers. So how does it show you a photo, play a song or display this sentence? The answer is a clever trick:
If you can turn something into numbers, a computer can store it, copy it and change it.
Let us see how that works for text, pictures and sound.
Text: a number for every letter
To store a letter, we simply agree on a number for each one. A famous agreement called ASCII says that A is 65, B is 66, C is 67, and so on. Small letters have their own numbers: a is 97. A space is 32.
Here is the word HI:
| Letter | Number | In binary (8 bits) |
|---|---|---|
| H | 72 | 01001000 |
| I | 73 | 01001001 |
The computer stores two bytes, and when it wants to show them, it looks up which letters they stand for.
You can try this. Make the number 65 with these switches:
0All switches are off, so the number is 0.
ASCII only covers English letters. Today's standard, Unicode, gives a number to well over a hundred thousand characters: letters in almost every language, symbols, and emoji.
Pictures: a grid of tiny squares
A picture on a screen is a grid of tiny coloured dots called pixels. If you zoom in far enough, you can see them.
The simplest picture has only black and white pixels. Each pixel needs just one bit: 1 for dark, 0 for light. Paint a tiny picture here, and look at the numbers on the right:
- 01010= 10
- 11111= 31
- 11111= 31
- 11111= 31
- 01110= 14
- 00100= 4
- 00000= 0
Each row of five pixels is a five-bit number. The whole heart is just seven numbers!
Colour
For colour, each pixel needs more than one bit. A common method describes every colour using three amounts, red, green and blue, each from 0 to 255. Mix them like coloured lights:
- (255, 0, 0) is pure red
- (255, 255, 255) is white: all three at full
- (0, 0, 0) is black: none at all
- (255, 140, 0) is the orange above
Each colour uses 3 bytes. A full-screen picture of 1,920 × 1,080 pixels has about 2 million pixels, so uncompressed it would need about 6 million bytes. Clever tricks called compression squash it down so that photos take far less space.
A video is just many pictures shown one after another, often 24 to 60 every second.
Sound: measure the wave again and again
Sound is a wave of air pressure. To store it, the computer measures the wave at regular moments, very quickly, and writes each measurement down as a number.
CD-quality sound takes 44,100 measurements every second. To play it back, the computer turns those numbers into a wave again with a speaker. If you measure often enough, your ear cannot tell the difference from the original.
Why does this matter?
Once something is numbers, a computer can do things with it:
- Copy it perfectly, as many times as you like.
- Change it: brighten a picture by adding to every number, or make a song louder.
- Search it: find a word in a book in a blink.
- Send it across the world, as a long list of numbers.
- Look for patterns in it. This will be very important when we reach AI.
When an AI "looks" at a photo, it does not see a cat. It sees a big grid of numbers. Machine learning is about finding patterns in those numbers.
Words to know
- ASCII
- An agreement that gives each English letter and symbol a number.
- Unicode
- A bigger agreement that covers letters from almost every language, plus emoji.
- Pixel
- One tiny dot in a picture. Each pixel is stored as one or more numbers.
- RGB
- Red, green and blue: three amounts that mix to make any colour on a screen.
- Compression
- A way of storing the same information in fewer bytes.
- Sample
- One measurement of a sound wave at one moment.
Check yourself
Which number stands for the letter A in ASCII?
Show the answer
65.
How many bits does a black-and-white pixel need?
Show the answer
Just one: 1 for dark, 0 for light.
What three amounts make up a colour on a screen?
Show the answer
Red, green and blue, each from 0 to 255.
How does a computer store a sound?
Show the answer
It measures the sound wave many thousands of times a second and stores each measurement as a number.