Everything is numbers: text, pictures and sound

Beginner6 min readPart 3 of 9

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:

LetterNumberIn binary (8 bits)
H7201001000
I7301001001

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:

128
64
32
16
8
4
2
1

0All switches are off, so the number is 0.

Each switch is worth double the one to its right. Add up the switches that are on to get the number.

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
Dark squares are 1 and light squares are 0. Each row is a 5-bit number, so the whole picture is just 7 numbers.

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:

Red255Green140Blue0=(255, 140, 0)hex #FF8C00
Every pixel has three numbers from 0 to 255. Together they make one colour. This orange is (255, 140, 0).

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.

0478399905914-35-75-97-95-70-282165the numbers stored:
To store sound, the computer measures the wave many times every second. CD-quality sound takes 44,100 measurements a second.

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:

A big idea for later

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

  1. Which number stands for the letter A in ASCII?

    Show the answer

    65.

  2. How many bits does a black-and-white pixel need?

    Show the answer

    Just one: 1 for dark, 0 for light.

  3. What three amounts make up a colour on a screen?

    Show the answer

    Red, green and blue, each from 0 to 255.

  4. 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.