Unicode
Why computers need numbers before they can touch text at all.
By the end of this chapter, you'll be able to:
- Explain why a CPU can't operate on letters directly
- Use ord() and chr() to move between characters and code points
- Understand why ASCII wasn't enough and what Unicode/UTF-8 fixed
The constraint behind everything in this handbook
A CPU has no instruction for "letter." It has instructions for arithmetic on numbers. Every chapter from here on is really about different ways of turning things into numbers — this one is where that story starts.
Every character is already a number
When you type the letter A, nothing resembling a letter is ever stored anywhere.
What's stored is a number — specifically 65. Your font renderer looks up 65 and
draws a glyph that looks like "A" on your screen, but the underlying representation
never leaves number-land.
Python exposes this directly with two built-in functions: ord() goes from a
character to its number, and chr() goes back.
text = "Hello SIGNAL"
print(text)
for ch in text:
print(ch, ord(ch))Run this and you'll see output like:
H 72
e 101
l 108
l 108
o 111
32
S 83
I 73
G 71
N 78
A 65
L 76Character 'H'
ord('H') → 72
Character 'e'
ord('e') → 101
Character 'l'
ord('l') → 108 (both ls share this — same character, same code point)
Character ' ' (space)
ord(' ') → 32 — even whitespace is a code point
Every single character — including the space — has a number. That number is called a code point.
Why not just use ASCII?
The first widely-used standard, ASCII, assigned numbers 0–127 to the English alphabet, digits, punctuation, and a handful of control codes. That's only 128 possible characters — enough for English, but nowhere close to enough for the rest of the world's writing systems, let alone emoji.
Unicode replaced that idea with a single, enormous table: over 1.1 million
possible code points, shared by every script humanity uses — Latin, Cyrillic,
Devanagari, Han characters, and everything else — plus symbols, punctuation, and
emoji, all living in the same numbering space. ord("A") and ord("あ") are both
asking the same question: "what number does Unicode assign to this character?"
Why this matters for a language model
A model can't accept "text" as input any more than a CPU can. Before a single weight or embedding is involved, every character in a training corpus has already gone through exactly the transformation you just ran: character → code point → number. Tokenization, which is next, builds directly on top of this — it just groups those numbers into more meaningful chunks than one-character-at-a-time.
Check your understanding
1. What does ord('A') return?
2. Why wasn't ASCII sufficient for global text processing?
3. What is the relationship between Unicode and UTF-8?
Interview questions
Interview questions
Tokenizers for large language models rarely operate on raw Unicode code points — they operate on UTF-8 bytes (this is what byte-pair encoding, covered in the next chapter, is built on). Why might operating on bytes, rather than code points, make a tokenizer more robust across languages it has never explicitly been trained on?