ViewWiki

Lesson 4 of 4

Images and text as numbers.

About 25 minutes · 6 practice questions

The size of a picture: resolution, colour depth and bytes, and why doubling the width makes the file four times bigger; and text as numbers, from ASCII to Hebrew letters in UTF-8.

Step 1 of 6 · Resolution

Step 1 of 6

Resolution

A digital picture is a grid of pixels. Its resolution is how many pixels it has across and down; here the picture keeps a 4 : 3 shape, so its height is three quarters of its width. The more pixels, the smoother the edges, and the bigger the file.

The picture is now 32 pixels across, and the board shows the number of pixels and the size. Predict, and then Pixels across will double.

To the question

Step 2 of 6

The file size

The size of an uncompressed picture is a simple sum:

B=P×3×s8B = \frac{P \times 3 \times s}{8}⁠

where BB⁠ is the size in bytes, PP⁠ the number of pixels and ss⁠ the bits per channel: three channels per pixel, and dividing by 88⁠ turns bits into bytes. Real files, like JPEG and PNG, compress these numbers, but the screen always shows the full picture.

To the question

Step 3 of 6

Resolution against colour

The same file size can be reached two ways: more pixels with fewer bits each, or fewer pixels in rich colour. Small icons and the pictures in old games gave up colours to save space.

To the question

Step 4 of 6

Letters as numbers

Text is numbers too. An encoding is a table that gives every character a number, and the computer stores only the numbers. The old encoding, ASCII, from the 1960s, numbers every Latin letter, digit and punctuation mark: A is 6565⁠, a is 9797⁠, the digit 0 is 4848⁠ and the space 3232⁠. It has 128128⁠ characters, seven bits, so each character fits in one byte.

To the question

Step 5 of 6

A word

A word is just a run of characters, and each one is stored separately, in order. Spaces and punctuation marks are characters too, and take room like a letter.

To the question

Step 6 of 6

Every language

ASCII has no room for Hebrew, Arabic, Chinese or emoji. Unicode gives a number to every character in every script in the world, more than a hundred and fifty thousand of them. The UTF-8 encoding stores them in one to four bytes: ASCII characters stay at one byte, so old text works as before, and other characters take more.

To the question

Interactive scene

Loading the interactive version…

Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.

To the experiment

Practice · Predict, then look

The picture is 32 pixels across. When Pixels across doubles to 64, how many times bigger will the uncompressed file be?

To the experiment

Practice · Calculate

The picture is 64×4864 \times 48⁠ pixels, at 8 bits per channel, and the board rounds its size to kilobytes. Exactly how many bytes does it take uncompressed?

To the experiment

Practice · Reach the target

You need a small icon that takes exactly 576 bytes, at 2 bits per channel. Change Pixels across and Bits per channel until it does, and press Check.

To the experiment

Practice · Calculate

In ASCII each character is a number, and the capital letters come in order: A is 6565⁠, B is 6666⁠. Which number stores the letter D?

To the experiment

Practice · Choose

How many bytes does the word HELLO take in ASCII?

To the experiment

Practice · Choose

In UTF-8, the encoding of most of the web, how many bytes does the Hebrew word שלום (four letters) take?