---
title: "Text, Pictures and Sound as Numbers"
book: "Primary & Middle School Computer Science"
subject: computer-science
language: en
chapter: 12
exercises: 11
source: https://one-course.com/books/computer-science/1/en/chapter/12-text-pictures-and-sound-as-numbers
license: CC-BY-NC-SA-4.0
credit: "One Computer Science Book, One Course (one-course.com)"
---

# Chapter 12 — Text, Pictures and Sound as Numbers

Lina sends a message to her cousin: “HI”. Her cousin’s phone, far away, shows the two letters a moment later. But no letter travelled along the cables: what travelled was sixteen [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit), sixteen 0s and 1s. A [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) keeps only [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit), so a letter, a photo and a song must all become numbers first. This chapter shows how.

**You already know.**

A [bit](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit) is a choice between 0 and 1; a [byte](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte) is eight [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit) and holds a whole number from 0 to 255; numbers can be written in [binary](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-binary) ([Chapter 11](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#ch-g5-bits-and-bytes)).

## 12.1 Every character has a number

**Definition 12.1 (Character code).**

A *character code* is the number given to a character (a letter, a digit, a sign, the space) by a *code table*, a table agreed by everyone, so that all [computers](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) turn the same character into the same number.

| A | B | C | D | E | F | G | H | I | J | K | L | M |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
| N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |

*small letters: a is 97, b is 98, …, z is 122 digits: 0 is 48, 1 is 49, …, 9 is 57 the space: 32*

A word becomes a list of numbers, one for each character, and each number fits in one [byte](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte). “HI” is 72 and 73; in [binary](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-binary), on one [byte](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte) each, it is 01001000 01001001: sixteen [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit).

![“HI” on its way: characters, then numbers, then bits.](https://one-course.com/images/onecourse/chapters/computer-science-1/g5-text-pictures-sound-as-numbers/fig-acaf17af6c7f.svg)

*“HI” on its way: characters, then numbers, then [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit).*

**History — A table agreed by everyone.**

The table used here comes from the American code for exchanging information, known as ASCII, in its version of 1968. It gives numbers to the English letters, the digits, the signs and a few control codes, 128 characters in all. Later, a much larger table was made, with a number for every character of every alphabet, Chinese characters and emoji included; it keeps the same numbers for the characters of this small table.

## 12.2 A picture is a grid of pixels

Look at a screen through a magnifying glass: the picture is made of tiny squares, in rows and columns, each of one single colour.

**Definition 12.2 (Pixel).**

A *pixel* is one of the tiny squares, all of one colour, that make up a picture on a screen or in a [file](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file), arranged in rows and columns.

The simplest pictures are black and white: each [pixel](#def-g5-text-pictures-sound-as-numbers-pixel) is black or white, so one [bit](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit) is enough for it, 1 for black and 0 for white.

![A smiley of 8 by 8 pixels and its 64 bits: 1 for a black pixel, 0 for a white one, one row of bits for each row of pixels.](https://one-course.com/images/onecourse/chapters/computer-science-1/g5-text-pictures-sound-as-numbers/fig-d6f573f43066.svg)

*A smiley of 8 by 8 [pixels](#def-g5-text-pictures-sound-as-numbers-pixel) and its 64 [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit): 1 for a black [pixel](#def-g5-text-pictures-sound-as-numbers-pixel), 0 for a white one, one row of [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit) for each row of [pixels](#def-g5-text-pictures-sound-as-numbers-pixel).*

**Definition 12.3 (Grey level).**

The *grey level* of a [pixel](#def-g5-text-pictures-sound-as-numbers-pixel) is a number from 0 to 255 that tells how light it is: 0 is black, 255 is white, and the numbers between are greys, darker for small numbers and lighter for large ones.

A [grey level](#def-g5-text-pictures-sound-as-numbers-grey) fits in one [byte](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte). For colours, a screen mixes light.

**Definition 12.4 (RGB colour).**

An *RGB colour* is a colour given by three numbers, each from 0 to 255: how much red, how much green and how much blue light to mix.

![Mixing light. Each pixel of a screen is three tiny lights, red, green and blue; the three numbers of the pixel set how bright each one is.](https://one-course.com/images/onecourse/chapters/computer-science-1/g5-text-pictures-sound-as-numbers/fig-6c1fb96b8f70.svg)

*Mixing light. Each [pixel](#def-g5-text-pictures-sound-as-numbers-pixel) of a screen is three tiny lights, red, green and blue; the three numbers of the [pixel](#def-g5-text-pictures-sound-as-numbers-pixel) set how bright each one is.*

Mixing light is not like mixing paint: red and green light together look yellow, and all three at full strength look white. (255, 0, 0) is pure red, (0, 0, 0) is black, and (255, 255, 255) is white.

![A drawing on a tablet: every stroke changes the three numbers of many pixels.](https://one-course.com/images/onecourse/chapters/computer-science-1/g5-text-pictures-sound-as-numbers/img-c5dfda6096da.jpg)

*A drawing on a tablet: every stroke changes the three numbers of many [pixels](#def-g5-text-pictures-sound-as-numbers-pixel).*

## 12.3 More pixels, more detail, a bigger file

**Definition 12.5 (Resolution).**

The *resolution* of a picture is its number of [pixels](#def-g5-text-pictures-sound-as-numbers-pixel), given as columns by rows: 8 by 8, or $1920$ by $1080$.

![The same round shape at two resolutions. With more pixels, the edge is smoother; the picture also needs more numbers.](https://one-course.com/images/onecourse/chapters/computer-science-1/g5-text-pictures-sound-as-numbers/fig-cab785024431.svg)

*The same round shape at two [resolutions](#def-g5-text-pictures-sound-as-numbers-resolution). With more [pixels](#def-g5-text-pictures-sound-as-numbers-pixel), the edge is smoother; the picture also needs more numbers.*

**Example 12.6 (The size of a picture).**

A small picture of 400 by 300 [pixels](#def-g5-text-pictures-sound-as-numbers-pixel) has $400 \times 300 = 120\,000$ [pixels](#def-g5-text-pictures-sound-as-numbers-pixel). Kept as three [bytes](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte) per [pixel](#def-g5-text-pictures-sound-as-numbers-pixel), one for each colour, it takes $120\,000 \times 3 = 360\,000$ [bytes](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte): 360 [kilobytes](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-units). Twice as many columns and twice as many rows make four times as many [pixels](#def-g5-text-pictures-sound-as-numbers-pixel), and a [file](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file) four times as big.

## 12.4 Sound as a long list of numbers

Sound is air that shakes back and forth very fast. A microphone turns the shaking into an electric signal, and the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) measures that signal many thousands of times every second: each measurement is a number. A song is a very long list of such numbers. To play it back, the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) sends the numbers to a speaker, in the same order and at the same speed, and the speaker shakes the air in the same way: we hear the sound again.

![A sound as a wave (blue) and the measurements a computer keeps (red dots): one number at each tick of a clock.](https://one-course.com/images/onecourse/chapters/computer-science-1/g5-text-pictures-sound-as-numbers/fig-4e1e4f7b5670.svg)

*A sound as a wave (blue) and the measurements a [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) keeps (red dots): one number at each tick of a clock.*

## 12.5 Everything in a file is bits

Text, pictures, sounds, films and [programs](https://one-course.com/books/computer-science/1/en/chapter/9-programs-and-the-operating-system#def-g4-programs-and-operating-system-program) are all kept in the same way: as numbers, and so as [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit). The [program](https://one-course.com/books/computer-science/1/en/chapter/9-programs-and-the-operating-system#def-g4-programs-and-operating-system-program) that reads a [file](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file) must know how the [program](https://one-course.com/books/computer-science/1/en/chapter/9-programs-and-the-operating-system#def-g4-programs-and-operating-system-program) that wrote it put the [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit) together. Many kinds of [file](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file) begin with a few [bytes](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte) that name their kind, and the [extension](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-extension) of a [file name](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file) ([Chapter 7](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#ch-g3-files-and-folders)) tells the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) which [program](https://one-course.com/books/computer-science/1/en/chapter/9-programs-and-the-operating-system#def-g4-programs-and-operating-system-program) to try: one that knows how to turn these [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit) back into letters, colours or sounds.

## 12.6 Exercises

**Exercise 12.1 ★.**

Write the word “CAT” as a list of [character codes](#def-g5-text-pictures-sound-as-numbers-code).

**Solution of Exercise 12.1.**

C is 67, A is 65, T is 84: 67, 65, 84.

**Exercise 12.2 ★.**

Which word do the codes 79 and 75 make?

**Solution of Exercise 12.2.**

79 is O and 75 is K: “OK”.

**Exercise 12.3 ★.**

Why do “A” and “a” have different codes?

**Solution of Exercise 12.3.**

They are different characters: the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) must know which one to show. A [code table](#def-g5-text-pictures-sound-as-numbers-code) gives every character its own number.

**Exercise 12.4 ★.**

Draw the picture of 5 by 5 [pixels](#def-g5-text-pictures-sound-as-numbers-pixel) given by these rows of [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit) (1 for black): 00100, 01110, 11111, 01110, 00100.

**Solution of Exercise 12.4.**

A black diamond in a white square:

![](https://one-course.com/images/onecourse/chapters/computer-science-1/g5-text-pictures-sound-as-numbers/fig-dd81bd559d9b.svg)

**Exercise 12.5 ★.**

What is the [grey level](#def-g5-text-pictures-sound-as-numbers-grey) of a white [pixel](#def-g5-text-pictures-sound-as-numbers-pixel)? Of a black one?

**Solution of Exercise 12.5.**

White: 255. Black: 0.

**Exercise 12.6 ★.**

Give the three numbers of a [pixel](#def-g5-text-pictures-sound-as-numbers-pixel) of pure red, then of pure blue.

**Solution of Exercise 12.6.**

Pure red: (255, 0, 0). Pure blue: (0, 0, 255).

**Exercise 12.7 ★.**

A colour picture of 10 by 10 [pixels](#def-g5-text-pictures-sound-as-numbers-pixel) is kept with three [bytes](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte) per [pixel](#def-g5-text-pictures-sound-as-numbers-pixel). How many [bytes](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte) does it take?

**Solution of Exercise 12.7.**

$10 \times 10 = 100$ [pixels](#def-g5-text-pictures-sound-as-numbers-pixel), and $100 \times 3 = 300$ [bytes](https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage#def-g4-memory-and-storage-byte).

**Exercise 12.8 ★.**

Read the third row of [bits](https://one-course.com/books/computer-science/1/en/chapter/11-bits-and-bytes-counting-in-binary#def-g5-bits-and-bytes-bit) of the smiley. What part of the face does it draw?

**Solution of Exercise 12.8.**

10100101: black [pixels](#def-g5-text-pictures-sound-as-numbers-pixel) at the two edges (the outline of the face) and at the third and sixth places: the two eyes.

**Exercise 12.9 ★★.**

Which colour does the [pixel](#def-g5-text-pictures-sound-as-numbers-pixel) (255, 255, 0) show? And (0, 255, 255)?

**Solution of Exercise 12.9.**

(255, 255, 0) is full red and full green light, no blue: yellow. (0, 255, 255) is green and blue: cyan, a light blue-green.

**Exercise 12.10 ★★.**

A picture of 100 by 100 [pixels](#def-g5-text-pictures-sound-as-numbers-pixel) and a picture of 200 by 200 [pixels](#def-g5-text-pictures-sound-as-numbers-pixel) are kept the same way. How many times bigger is the second [file](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file)?

**Solution of Exercise 12.10.**

$100 \times 100 = 10\,000$ [pixels](#def-g5-text-pictures-sound-as-numbers-pixel) against $200 \times 200 = 40\,000$: the second [file](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file) is 4 times bigger.

**Exercise 12.11 ★★.**

The digit 7 is a character too. Its code is not 7: what is it? Why can the code of a digit not simply be the digit itself?

**Solution of Exercise 12.11.**

The code of the character 7 is 55 (0 is 48, 1 is 49, …). The small numbers of the table are already used for other things (the space is 32, and the numbers below it are control codes), and a text must be able to hold the character 7 without mixing it up with the number seven that a [program](https://one-course.com/books/computer-science/1/en/chapter/9-programs-and-the-operating-system#def-g4-programs-and-operating-system-program) counts with.
