All episodes · From One Switch to a CPU · Episode 6

How Computers Store Text, Colors and Sound as Numbers

Pressing play loads the video from YouTube.

Letters, photos, songs: inside a computer, everything is numbers.
We look at ASCII and why 65 means A, how Unicode and UTF-8 fit the world's writing systems into bytes, how a pixel mixes red, green and blue, and how sound is sampled 44,100 times a second. Then the same bytes read three different ways.

Every animation in this video is drawn by code, and the narration is an AI voice.

Transcript

This is the letter A. This is a shade of orange. And this is a short beep. Inside a computer, all three are just numbers. Today: how numbers become text, pictures and sound, and why the numbers alone don't tell you which is which.

Start with text. The idea is simple: give every character a number, and everyone agrees on the list. One early list, called ASCII, comes from the nineteen-sixties. Capital A is sixty-five. B is sixty-six, and so on. Small a is ninety-seven. A space is thirty-two. Even the digit seven has its own number: fifty-five. So the word “Hi” is stored as seventy-two, one hundred five. Two bytes, sixteen bits. ASCII uses seven bits, which gives room for one hundred twenty-eight characters. Enough for English, but not for the rest of the world. Today there's one list for nearly every writing system, called Unicode. It holds about one hundred fifty thousand characters, with room for over a million. Accented letters, Cyrillic, Japanese, Chinese, Korean: each character gets its own number. To save space, a format called UTF-8 stores common characters in one byte, and others in two, three or four. A takes one byte. This Chinese character takes three.

Now pictures. Zoom into any screen, and you'll find a grid of tiny squares called pixels. Each pixel mixes three lights: red, green and blue. Each light gets one byte, a number from zero to two hundred fifty-five, for how bright it is. All three at zero make black. All three at full make white. Red at full, green at two thirds and blue off make orange. Three bytes are enough for over sixteen million colors. A picture is just these numbers, row after row. A full HD screen has about two million pixels, so one picture is about six million numbers. That's why photos and videos are usually compressed: stored in a smarter way that needs far fewer numbers.

And sound? Sound is air pressure going up and down, very fast. A microphone turns that pressure into a voltage that rises and falls the same way. To store it, the computer measures the voltage at regular moments. Each measurement is a sample. Music is often sampled forty-four thousand one hundred times every second, and each sample is a sixteen-bit number. Why so often? To capture a wave, you need at least two samples per wave. Human hearing reaches about twenty thousand waves a second, so forty-four thousand samples is just enough. To play it back, the numbers go out to a speaker as voltages, and the speaker pushes the air. Sound again.

Here's the strange part. The same three bytes, seventy-two, one hundred five, thirty-three, could be anything. Read as text, they say “Hi!”. Read as a pixel, they're this olive green. Read as sound, they're three tiny steps of a wave. The bytes don't know what they are. The program reading them decides, often from a hint like the end of the file name.

So: text is numbers from an agreed list, pictures are numbers for light, and sound is numbers measured over time. But every circuit we've built so far forgets the moment its inputs change. Next time, we build circuits that remember. See you there.

Next episode: a circuit that remembers. Latches, flip-flops and registers.

Buy the Developer a Coffee

Entirely up to you: it works the same either way.

Every cup turns into the next update.

WeChat Pay QR code
WeChat Pay
Alipay QR code
Alipay
PayPal QR code
PayPal