Unit 1 · Digital Information · Lesson 1.4

Text as Bits

A computer has never once seen a letter. It sees numbers, and it has been told what they mean.

Big Idea 2 — Data

Before this lesson — read on Runestone

You skimmed this in 0.2 for the byte. This time read it for the table. Enrolled in our Runestone course? Open it from there so your progress counts.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

Still in Bits. You can now turn numbers into bits and back (1.2), and you know what happens when a number outgrows its bits (1.3). Everything so far has been about numbers. Starting now, we use numbers to represent things that aren't numbers — and text is the first one.

2

The Hook

89 111 117 32 97 114 101 32 114 101 97 100 105 110 103 32 110 117 109 98 101 114 115 That is a sentence. It is currently twenty-three numbers, and you have everything you need to read it — a lookup table is sitting a few sections down this page.

Decode it. Then notice what just happened: nothing about those numbers is text. They became text because you applied an agreement. Your computer does exactly the same thing, millions of times a second, and it is no more "reading" than you were.

3

The Idea

A wire carries bits. Bits make numbers. So to send a letter, somebody had to sit down and decide which number is the letter A — and then get everyone else to agree. That agreement is called a character encoding, and the one that won is ASCII, standardized in 1963.

ASCII uses 7 bits per character, which gives 27 = 128 slots. Each slot holds one character.

128 slots is enough for the uppercase letters, the lowercase letters, the ten digits, punctuation, and a set of control codes like "newline." Here are the four numbers worth memorizing, because they anchor the whole table:

CharacterDecimalBinary (8-bit)Why it matters
space3200100000A space is a character. It costs a byte like anything else.
'0'4800110000The character zero, not the number zero.
'A'6501000001Uppercase starts here and runs to 'Z' = 90.
'a'9701100001Lowercase starts here and runs to 'z' = 122.

Look hard at the last two rows. 97 − 65 = 32, and 32 is a power of 2 — which means uppercase and lowercase differ by exactly one bit:

A  01000001  =  65
a  01100001  =  97
     โ†‘ this bit, worth 32, is the entire difference

That was not luck. The people who designed ASCII arranged the table so that changing case is a single bit flip, which made it fast and cheap on 1963 hardware. You'll flip that bit yourself in a minute.

The mistake that costs points. The character '7' is not the number 7. '7' is ASCII 55. If a program adds '7' + '7' as text it gets '77'; if it adds them as numbers it gets 14. Nearly every "why is my program doing that" moment in Unit 2 traces back to this distinction.

When 128 stopped being enough

ASCII was designed by an American committee for American English. It has no é, no ñ, no ü. No Greek, no Cyrillic, no Arabic, no Hebrew, no Devanagari. No Chinese — and Chinese alone needs thousands of characters, which will not fit in 128 slots no matter how the slots are arranged.

Stretching to 8 bits bought 256 slots. Still nowhere near enough. What actually solved it was Unicode, begun in 1991, which gave every character in every writing system its own number — currently well over 150,000 of them, in a space with room for more than a million. Emoji live there too, which is why ๐Ÿ˜€ is not a picture your phone stores but a number your phone looks up and draws.

Unicode's common storage format, UTF-8, is deliberately backwards-compatible: any plain ASCII character still takes exactly one byte and still has exactly its old ASCII number. Characters outside ASCII take two, three, or four bytes. That is why an emoji costs four times what a letter costs, and you can watch that happen in the encoder below.

What the AP exam expects. You need to know that text is represented as numbers by an agreed-upon encoding, and you need to reason about how many bits a given number of characters requires. You are not expected to memorize the ASCII table — any question that needs specific values will give them to you. Know the concept and the arithmetic; look up the rest.
4

Try It

The table

Here is the lookup table the hook promised. Decode the hook first, on paper, before you touch the widget.

space32
048
149
250
351
452
553
654
755
856
957
A65
B66
C67
D68
E69
F70
G71
H72
I73
J74
K75
L76
M77
N78
O79
P80
Q81
R82
S83
T84
U85
V86
W87
X88
Y89
Z90
a97
b98
c99
d100
e101
f102
g103
h104
i105
j106
k107
l108
m109
n110
o111
p112
q113
r114
s115
t116
u117
v118
w119
x120
y121
z122

Encode your initials, by hand

Write your first and last initial. Look up each one in the table above. Convert both numbers to 8-bit binary using the method from 1.2 — subtract the largest power of 2 that fits, and pad with leading zeros until you have eight digits.

Now trade with a partner and decode theirs. Then answer this without checking: if your initials were lowercase instead, which single bit would change in each byte?

Now let the machine do it. Type anything — your name, the hook sentence, an emoji.

Type text. Each character becomes a number, then bits.

The one-bit case flip. Type a single letter and watch which bit does the work.

In Unit 2 you stop doing this by hand. Python has two functions that are this lookup table:

print(ord('A'))    โ†’ 65        # character โ†’ number
print(chr(97))     โ†’ 'a'       # number โ†’ character
print(ord('a') - ord('A'))  โ†’ 32   # the case gap, confirmed
5

Vocabulary

You just used all three of these. Now they get names.

character encoding Bits
An agreed-upon mapping between characters and numbers, so that text can be stored and sent as bits.
ASCII Bits
A 7-bit character encoding standardized in 1963, with 128 slots covering English letters, digits, punctuation, and control codes.
Unicode Bits
A character encoding standard that assigns a unique number to every character in every writing system, plus symbols and emoji — far beyond ASCII's 128 slots.
6

Check

Five questions in AP format. Pick an answer to see feedback immediately.

0 of 5 answered
7

Impact Check

Whose alphabet fit in 128 slots?

ASCII was not neutral. It was designed in the United States, in 1963, for English, and its 128 slots have room for every letter an English speaker needs and not one character more. That was a reasonable engineering decision under real hardware limits — and it became the default for computing worldwide.

The consequence lasted decades. If your language used accents, a different alphabet, or thousands of characters, you either worked in English or you used one of many incompatible regional workarounds, where the same byte meant a different character depending on which country's system opened the file. Text that looked fine when you sent it arrived as garbage.

Unicode largely fixed the standard. It did not fix every system built on the old assumption, which is why people whose names contain characters outside ASCII still find them silently stripped, replaced with question marks, or rejected by forms — on boarding passes, medical records, and government paperwork. A limit chosen for good reasons in 1963 is still, occasionally, deciding whose name is spelled correctly.

8

Connections

Came from 1.2 — you converted 65 to binary without being told how. That fluency is now doing real work.
Came from 1.3 — ASCII's 128 slots is the same 2n ceiling that broke the view counter. Running out of characters and running out of numbers are the same problem wearing different clothes.
Next in 1.5 — same move again, for color. A pixel is three numbers, and the only new idea is which numbers mean what.
Returns in Unit 2 — ord() and chr() let Python do this lookup for you, and '7' vs 7 becomes a bug you have to actually fix.
← 1.3 When Numbers Break