Chapter 1: What is Text, Really? From Stories to Strings
When you type the word "hello" on your keyboard and press Enter, something magical happens. Instantly, your message appears on your friend's screen miles away. But what does your computer actually *do* with those letters? It doesn't "read" like you do—it doesn't understand that "hello" is a greeting, or that the letter 'h' has a certain shape and sound. Instead, your computer sees something entirely different: a sequence of numbers. This chapter is about that fundamental transformation—the moment human language becomes computer data. We'll explore how text, something we interact with every day, is broken down into its tiniest pieces, translated into numbers, and stored as strings of digits. We'll meet the secret codes (ASCII and Unicode) that act as dictionaries between letters and numbers, and you'll learn to write your name in the binary language of computers. By the end, you'll see that every emoji, every text message, every digital book is just a cleverly organized string of numbers waiting to be interpreted. Let's decode the magic!
Imagine you're telling a story to a robot. You say, "Once upon a time..." The robot's ears (microphone) capture sound waves. Its brain (processor) needs to understand what you said, but it only knows about electricity and switches that can be ON (1) or OFF (0). So, somehow, your beautiful story must become a long, long list of 1s and 0s. That list is the computer's version of your story. It's not the story itself—it's a *representation* of the story, a code. This chapter is about that code. We'll learn how we go from "Once upon a time..." to `01010011 01110100 01101111 01110010 01111001` (which is actually "Story" in ASCII binary). It's like learning the secret handshake that lets humans and machines talk to each other.
What is text, really? At its most basic level, text is a sequence of characters. A character is any symbol we use to write: letters (a, b, c...), digits (0, 1, 2...), punctuation (., !, ?), spaces, and even invisible control characters. When we write a sentence, we're arranging these characters in a specific order. The meaning comes from that order. "Dog" is different from "God" because the letters are in a different sequence. So, text is fundamentally *ordinal*—order matters.
But here's the key difference between you and your computer:
- **Human Reading:** Your brain is a meaning-making machine. You see the shapes of letters, recognize them as symbols, combine them into words, and instantly connect those words to concepts, memories, and emotions. When you read "dog," you might picture a furry animal, remember your pet, or think of the sound "woof." Your understanding is rich, contextual, and full of associations.
- **Computer Reading:** A computer has no inherent understanding of meaning. It doesn't know what a dog is. It only knows about patterns of electricity. Its job is to *process* the symbols, not *understand* them. It counts characters, finds patterns, moves them around, and stores them. It's like a librarian who can perfectly organize books by their ISBN numbers but has never read a single book. The computer's "reading" is syntactic, not semantic.
This distinction is the bedrock of Natural Language Processing (NLP). Before a computer can *understand* text, it must first *represent* text. And that representation is always, at some level, a mapping from symbols to numbers.
Let's look at a simple sentence: "I am 10 years old." How many characters are there? Let's count carefully: `I` (1), space (2), `a` (3), `m` (4), space (5), `1` (6), `0` (7), space (8), `y` (9), `e` (10), `a` (11), `r` (12), `s` (13), space (14), `o` (15), `l` (16), `d` (17), period (18). There are 18 characters. But notice something: the space is a character too! It's an invisible one, but it's crucial. Without it, we'd have "Iam10yearsold," which is harder to read. So, in the computer's world, the space is just as much a symbol as the letter 'I'.
Now, how does the computer store these 18 characters? It needs a *codebook*, a dictionary that says: "The symbol 'I' corresponds to the number 73," "The symbol ' ' (space) corresponds to the number 32," and so on. This codebook is called a character encoding. The most famous early codebook is ASCII (American Standard Code for Information Interchange).
ASCII was created in the 1960s for early computers and telegraph machines. It's a 7-bit code, meaning it uses 7 binary digits (bits) to represent each character. 7 bits can represent $2^7 = 128$ different values (0 to 127). That's enough for the English alphabet (uppercase and lowercase), digits, common punctuation, and some control characters (like "line feed" or "carriage return").
Here's a simplified view of part of the ASCII table:
| Character | Decimal Code | Binary (7-bit) | |-----------|--------------|----------------| | (null) | 0 | 0000000 | | A | 65 | 1000001 | | B | 66 | 1000010 | | ... | ... | ... | | a | 97 | 1100001 | | b | 98 | 1100010 | | ... | ... | ... | | 0 | 48 | 0110000 | | 1 | 49 | 0110001 | | ... | ... | ... | | space | 32 | 0100000 | | ! | 33 | 0100001 | | . | 46 | 0101110 |
Notice the pattern? Uppercase letters start at 65 ('A'), lowercase at 97 ('a'), digits at 48 ('0'). This wasn't random; it was designed for convenience. The difference between 'A' and 'a' is exactly 32 (binary: 100000), which is just flipping the 6th bit (from the right, starting at 0). This makes case conversion easy for computers.
Let's encode our sentence "I am 10 years old." using ASCII:
- 'I' = 73 = `1001001` (7-bit, but computers usually store in 8-bit bytes, so it's `01001001`)
- ' ' = 32 = `0100000` (or `00100000` in 8-bit)
- 'a' = 97 = `1100001` (or `01100001`)
- 'm' = 109 = `1101101` (or `01101101`)
- ' ' = 32 = `00100000`
- '1' = 49 = `0110001` (or `00110001`)
- '0' = 48 = `0110000` (or `00110000`)
- ' ' = 32 = `00100000`
- 'y' = 121 = `1111001` (or `01111001`)
- 'e' = 101 = `1100101` (or `01100101`)
- 'a' = 97 = `01100001`
- 'r' = 114 = `1110010` (or `01110010`)
- 's' = 115 = `1110011` (or `01110011`)
- ' ' = 32 = `00100000`
- 'o' = 111 = `1101111` (or `01101111`)
- 'l' = 108 = `1101100` (or `01101100`)
- 'd' = 100 = `1100100` (or `01100100`)
- '.' = 46 = `0101110` (or `00101110`)
So the entire sentence becomes a long string of 0s and 1s: `01001001 00100000 01100001 01101101 00100000 00110001 00110000 00100000 01111001 01100101 01100001 01110010 01110011 00100000 01101111 01101100 01100100 00101110`. That's 18 bytes (since each character is 8 bits, or 1 byte). The computer doesn't see "I am 10 years old." It sees this exact sequence of 144 bits (18 × 8).
This transformation is lossless. If you have the ASCII table and this binary string, you can perfectly reconstruct the original sentence. There's a one-to-one mapping between characters and numbers (within the ASCII set).
But ASCII has a big problem: it only covers English letters and a few symbols. What about Chinese characters? Arabic? Cyrillic? Emojis? They're not in the 0-127 range. That's where Unicode comes in.
Unicode is the universal character encoding standard. Its goal is to assign a unique number (called a code point) to *every* character from *all* writing systems in the world, plus symbols, emojis, and even ancient scripts like Egyptian hieroglyphs. Unicode doesn't just define numbers; it also defines properties like "this is a letter," "this is a number," "this reads right-to-left," etc.
Unicode code points are usually written in the format `U+XXXX`, where XXXX is a hexadecimal (base-16) number. For example:
- 'A' is `U+0041` (hex 41 = decimal 65, same as ASCII)
- 'a' is `U+0061` (he