sciandu
Computer science

Computer science

Characters & codes

How letters become numbers: the trick computers use to store text.

What you need first

When you type a message, no letters travel through the network, only numbers. Your phone turns every character into a number, sends the numbers off, and your friend's phone turns them back into text. This simple trick sits behind every chat message, every web page, and every emoji.

Every character gets a number

The idea is called character encoding: everyone agrees on a table in which each character has a fixed number. The most famous old table is ASCII. There, A has the number 65, B is 66, C is 67 and so on, the alphabet simply numbered through. If you know the code of A, you can work out any capital letter: E is the fifth letter, so 65 + 4 = 69.

Character code
Code65
A
6501000001
A = 65 = 01000001
Try it: type characters and look up which number and which binary representation hide behind them.

Text is a sequence of numbers

A whole word is therefore just a sequence of numbers: HI becomes 72, 73. And since you can write numbers in binary, every text is ultimately a long chain of 0s and 1s, perfectly ordinary binary data. Every ASCII number fits into one , that is 8 bits. An ASCII character therefore costs exactly 1 byte of storage. Important: capital and small letters have different codes. The small a has the number 97, not 65. To the computer, A and a are two completely different characters.

Unicode: room for all characters

ASCII has only 128 slots, which is not even enough for ä, ö, and ü. That is why today we have Unicode: a huge table with numbers for practically every character in the world, from Chinese characters to special symbols to emojis. So your favourite emoji is just a number too, only a rather large one. And because such a large number no longer fits into a single byte, an emoji takes up several bytes of storage.

Exercises

0 of 6 solved

Time to try it yourself. You can't break anything, every attempt counts.

How does a computer store text?

The capital letter A has code 65. What code does the capital letter B have?

What code does the capital letter E have?

ASCII has only slots, which is not even enough for ä, ö, and ü.

Do A and a have the same code?

Match each term to the description that fits.

ASCII
Unicode
emoji

Where this leads