How does text become numbers
We said computers only understand numbers. Yet we type letters on a keyboard, and letters show up on the screen. In this lesson we look inside to see how a machine that only knows numbers handles text.
Every character has a number
The secret is simpler than you'd think.
People got together and gave every character a number.
A is 65, B is 66, and so on.
So when you press A on the keyboard, what reaches the computer isn't a letter but the number 65.
Tap a character to see its number.
Uppercase A to Z, lowercase letters, digits, and symbols all have their own numbers.
This agreement that assigns numbers to characters is called ASCII.
It was the first code table computers widely used for text.
The number becomes 0s and 1s again
Remember the last lesson: computers store numbers as 0s and 1s too.
So the number 65 is also stored, in the end, as eight switches turned on or off.
One character becomes eight 0s and 1s.
A is number 65, and that number turns into eight 0s and 1s.
So one English character usually takes up eight switches, which is 1 byte.
This is where the word for a group of eight, the byte, first appears.
Text, too, was 0s and 1s all along.
Opening up the code table
Below is what the ASCII table actually looks like.
The characters are lined up in number order, and each one has its number written next to it.
Uppercase A is 65, lowercase a is 97, and the digit 0 is 48.
For the same letter, the lowercase number is 32 more than the uppercase one.
Here's a fun detail: uppercase and lowercase letters are exactly 32 apart.
A is 65 and a is 97.
That's no accident. The table was set up that way on purpose so computers could switch case easily.
Eight switches aren't enough
Eight switches can show 256 different patterns.
Even after fitting in the English alphabet, digits, and symbols, there's room to spare.
Since the agreement was made in the English-speaking world, that was enough at first.
From 0 to 255: 256 values in all.
But the world doesn't run on English alone.
Korean has more than ten thousand syllable characters, and Chinese characters number in the tens of thousands.
Add emoji, and 256 doesn't come close.
So a new agreement was needed.
Bigger characters use more bytes
The fix is simple.
If one slot isn't enough, use several.
In UTF-8, the most common encoding, English stays at 1 byte, Korean usually takes 3 bytes, and an emoji takes 4 bytes.
This huge table that gives a number to every character in the world is called Unicode.
Different characters take up different numbers of slots.
So even a single character can take up different amounts of space.
An English letter takes one slot, a Korean character takes three.
That's why the character count you see in a message can differ from what the computer counts.
A sentence is just a line of numbers
Now let's look at one short line all at once.
Each character turns into a number, and each number turns back into 0s and 1s.
Every message we send is, underneath, a long line of numbers like this.
Hi, the way a computer sees it.
Showing text on a screen runs the same steps in reverse.
The computer reads the 0s and 1s, works out the number, finds the character for that number in the table, and draws it.
To our eyes it's text, but inside it's numbers from start to finish.