Representing Text

8 min✏️ Quiz at the end

The Problem: Computers Only Store Numbers

You already know the punchline of binary numbers: everything in a computer is stored as 0s and 1s — that is, as numbers. But this page you are reading is full of letters. How does "HELLO" fit into a machine that can only hold numbers?

The answer is beautifully simple: give every character a number. Not calculate it — just agree on it, the way countries agree that a red light means stop.

Character Codes and ASCII

A character set is that agreement: a table matching each character to a code number. The most famous is ASCII (American Standard Code for Information Interchange), agreed in the 1960s:

CharacterCodeBinary (8-bit)
A6501000001
B6601000010
C6701000011
a9701100001
0 (digit)4800110000
space3200100000

Spot the patterns: the alphabet runs in order (so D must be 68), uppercase and lowercase are separate characters exactly 32 apart, and even the space has a code — to a computer, a space is a character like any other. Note also that the digit "0" as a character is code 48, not the number 0 — the symbol and the value are different things.

So "HELLO" becomes:

H     E     L     L     O
72    69    76    76    79
01001000 01000101 01001100 01001100 01001111

Five characters, five bytes, forty bits. Every text you have ever sent made exactly this journey.

The Agreement Is Everything

Here is the crucial insight: 65 does not mean A. It means A only because sender and receiver agree it does. The number is just a number; the character set gives it meaning.

Break the agreement and you get chaos. If one program saves text using one character set and another program opens it assuming a different one, the numbers get decoded into the wrong characters — and you see garbage like C’est instead of C'est. If you have ever seen a page full of � symbols, you have witnessed a character-set mismatch. Debugging text like this always starts with the same question: which encoding was this written in?

Unicode — Text for the Whole World

ASCII has a serious limitation: only 128 codes. Enough for English letters, digits, and common symbols — and nothing else. No é, no ñ, no Greek, Arabic, Chinese, Hindi, or Korean. For decades, different regions bolted on their own incompatible extensions, and text exchanged between countries regularly turned to mush.

The fix is Unicode: one character set for every writing system on Earth. Unicode assigns a unique number — a code point — to more than 150,000 characters so far, with room for over a million:

  • Latin letters, including every accented variant
  • Chinese, Japanese, Korean, Arabic, Hebrew, Devanagari, Cyrillic, Greek…
  • Mathematical symbols, currency signs, ancient scripts
  • And yes — emoji. 😀 is code point 128512. When you text a friend a 🎂, your phone sends that character's number, in binary, chopped into packets.

Unicode deliberately kept its first 128 codes identical to ASCII, so the old standard lives on inside the new — a lovely example of upgrading a worldwide system without breaking what already worked.

Why Text Is Cheap

One byte per ASCII character (Unicode characters take one to four) makes text astonishingly compact. This entire lesson is a few kilobytes — while a single phone photo is a few megabytes, a thousand times more. The reason photos and sound cost so much more is the subject of representing images and sound.

Try It Yourself

Using A=65 … Z=90: decode 67 79 68 69. Then encode your initials into ASCII codes, and convert one of them to 8-bit binary using binary place values. Congratulations — you have hand-simulated what your keyboard does on every keypress.

Worked Example — Encoding a Whole Word by Hand

Watch the complete journey of the word "HI" from keypress to stored bits, one stage at a time:

  1. Keypress — you press the H key, then the I key
  2. Look up the code — ASCII says H is 72, I is 73
  3. Convert each code to binary — using the place-value method from binary numbers: 72 = 01001000, and 73 = 01001001
  4. Store the bits — these sixteen bits (two bytes) are what actually sits in memory or on a storage device
H  →  72  →  01001000
I  →  73  →  01001001

Notice this is genuinely nothing more than looking up a number and converting it to binary — two skills already covered separately in this course, now combined into one pipeline. Every character you have ever typed, in every app, on every device, went through exactly these same four steps.

Why Sorting Text Alphabetically Actually Works

Here is a detail that quietly relies on the design of ASCII: when a computer "sorts alphabetically", it isn't applying any special alphabet knowledge — it is simply comparing the underlying character codes as numbers, the same way it would compare any other numbers. Because A=65, B=66, C=67 and so on run in increasing order matching the alphabet, sorting by code number gives the same result as sorting alphabetically. This also explains a classic surprise: since uppercase letters (A=65 onward) all have smaller codes than lowercase letters (a=97 onward), a naive code-based sort will place "Zebra" before "apple" — Z (90) is still a smaller code than a (97) — unless the sorting program deliberately corrects for this by treating upper and lower case as equivalent first. This is exactly the kind of subtle rule that makes testing sorting features on real-world names (mixed case, accents, punctuation) so important.

Key Words

  • Character set — an agreed table matching characters to number codes
  • ASCII — the classic 128-character set covering English letters, digits, and symbols
  • Unicode — the universal character set covering all the world's scripts and emoji
  • Code point — a character's unique number in Unicode
  • Encoding — the scheme used to store character numbers as bytes