Representing Text Digitally
Welcome! Have you ever wondered how a computer knows what letter you just typed on your keyboard? Whether you are texting a friend, writing an essay, or searching the web, computers deal with millions of words every single second. But here is the big secret: computers cannot read or understand letters at all. Deep inside their microchips, computers are made up of tiny electronic switches (transistors) that only understand two states: on or off. In computing, we represent these states using the binary digits \(0\) and \(1\).
So, how does a computer turn binary numbers like \(01000001\) into the letter A? In this chapter, you will learn the clever systems computer scientists invented to represent human text using nothing but binary digits!
Don't worry if binary numbers feel a bit strange at first — by the end of this guide, you will see that it works just like a secret code!
---1. The Basics: Characters and Character Sets
What is a Character?
In computing, a character is a single unit of written information. A character can be:
• An uppercase letter (such as A, B, C)
• A lowercase letter (such as a, b, c)
• A number digit (such as 0, 1, 2 ... 9)
• A punctuation mark (such as ., !, ?, ,)
• A special symbol (such as £, $, %, +)
• A space (pressing the spacebar creates a real character!)
• A control code (invisible instructions like pressing Enter/Return, Backspace, or Escape)
What is a Character Set?
Imagine you and your friend have a secret decoder ring where every letter is assigned a special number: \(1 = A\), \(2 = B\), \(3 = C\), and so on. If you send your friend the numbers \(8 - 5 - 12 - 12 - 15\), they can decode it to read HELLO.
In computing, this decoder ring is called a character set. A character set is a predefined, standardised list of all the characters that a computer system can recognize, where every single character is given its own unique numeric value known as a character code (or code point).
The Number of States Formula
How many different characters can a computer store? It all depends on how many binary digits (bits) we use for each code!
Every time you add \(1\) extra bit, you double the number of possible characters you can represent. The mathematical formula is:
Number of unique characters \(= 2^n\)
(where \(n\) is the number of bits used per character)
• With \(1\) bit: \(2^1 = 2\) characters (\(0\) or \(1\))
• With \(2\) bits: \(2^2 = 4\) characters (\(00\), \(01\), \(10\), \(11\))
• With \(3\) bits: \(2^3 = 8\) characters (\(000\) to \(111\))
• With \(7\) bits: \(2^7 = 128\) characters
• With \(8\) bits: \(2^8 = 256\) characters
Key Takeaway: A character set is a complete list of characters paired with unique binary numbers so computers can store and display text.
---2. The ASCII Standard
What is ASCII?
In the early days of computing, different computer brands used their own custom codes. A file written on one computer could look like gibberish on another! To fix this, scientists created a universal standard called ASCII (pronounced "ASK-ee"), which stands for the American Standard Code for Information Interchange.
Standard 7-bit ASCII
• Uses \(7\) bits per character.
• Can represent \(2^7 = 128\) distinct characters (using character codes from \(0\) up to \(127\)).
• Includes all English uppercase letters (\(A\)–\(Z\)), lowercase letters (\(a\)–\(z\)), digits (\(0\)–\(9\)), common punctuation marks, the space character, and control characters like Backspace and Enter.
Extended 8-bit ASCII
As computers became more powerful, systems moved to using full \(8\)-bit bytes (where \(1\text{ byte} = 8\text{ bits}\)).
• Uses \(8\) bits per character.
• Can represent \(2^8 = 256\) distinct characters (using character codes from \(0\) up to \(255\)).
• The extra \(128\) codes (from \(128\) to \(255\)) allow Extended ASCII to include accented European letters (like é, ñ), extra currency symbols (like £), and basic graphical line-drawing symbols.
Logical Ordering (Collation) in ASCII
ASCII was designed very smartly! Characters are arranged in sequential, logical numerical order, which makes it easy for computers to sort words alphabetically.
Here are the key reference values you should remember:
• Uppercase 'A' has the denary code \(65\) (binary \(01000001\)).
• 'B' is \(66\), 'C' is \(67\) ... all the way to 'Z' which is \(90\).
• Lowercase 'a' has the denary code \(97\) (binary \(01100001\)).
• 'b' is \(98\), 'c' is \(99\) ... all the way to 'z' which is \(122\).
• Digits start at '0' with code \(48\), '1' is \(49\) ... up to '9' which is \(57\).
Handy Tip: The Magic Number 32
Notice the difference between uppercase and lowercase letters:
\(\text{Code for 'a'} - \text{Code for 'A'} = 97 - 65 = 32\)
To turn any uppercase ASCII letter into its lowercase version, you simply add \(32\) to its denary code! In binary, this simply means flipping bit position \(6\) from \(0\) to \(1\).
Limitations of ASCII
While ASCII worked well for English, it has one massive drawback: it is far too small. With only \(128\) or \(256\) possible codes, ASCII cannot represent world languages with large character systems or non-Latin alphabets (such as Chinese, Japanese, Arabic, and Russian), nor can it represent modern symbols like emojis.
Key Takeaway: Standard ASCII uses \(7\) bits (\(128\) characters) and Extended ASCII uses \(8\) bits (\(256\) characters). It covers English well, but cannot support all world languages.
---3. The Unicode Standard: A Universal Solution
Why was Unicode Created?
To solve the limitations of ASCII, computer scientists created Unicode. The goal of Unicode is to create a single, universal character set that can represent every written human language on Earth, mathematical and scientific symbols, ancient scripts, and modern emojis.
How Big is Unicode?
Unicode uses larger bit depths — typically up to \(16\) bits or \(32\) bits per character (using encoding formats like UTF-8, UTF-16, and UTF-32):
• A \(16\)-bit encoding allows \(2^{16} = 65,536\) unique characters.
• A \(32\)-bit encoding allows over \(4\text{ billion}\) characters (\(2^{32} = 4,294,967,296\) possible code points).
Did you know? Because of its enormous capacity, Unicode has plenty of space for thousands of emojis, from smiley faces 😊 to animals 🐼 and food 🍕!
Backward Compatibility
One of the best design choices of Unicode is that it is backward compatible with ASCII. This means the first \(128\) codes in Unicode (codes \(0\) to \(127\)) are completely identical to standard \(7\)-bit ASCII. A classic ASCII file can be read by any modern Unicode system without any errors.
ASCII vs. Unicode Comparison
• ASCII: Uses \(7\) or \(8\) bits per character. Stores \(128\) to \(256\) characters. Only covers English and a few Western European characters. Files take up less storage space.
• Unicode: Uses up to \(16\) or \(32\) bits per character. Stores millions/billions of characters. Covers all global languages, math symbols, and emojis. Requires more storage space per character when using larger bit depths.
Key Takeaway: Unicode is the modern global standard. It can store billions of characters and works with every major world language and emoji set, while remaining compatible with older ASCII text.
---4. Calculating Text File Sizes
Because every character needs a specific number of bits, calculating the storage size of a plain text file is straightforward.
The Storage Formula
$$\text{File size (bits)} = \text{Total number of characters} \times \text{Bits per character}$$
Remember: You must count all letters, digits, punctuation marks, AND spaces!
Worked Example 1: Extended ASCII (\(8\) bits per character)
Imagine you write a short message: "Hello World!"
Step 1: Count every character:
H-e-l-l-o (\(5\)) + [space] (\(1\)) + W-o-r-l-d-! (\(6\)) \(= 12\text{ characters in total}\).
Step 2: Multiply by the bits per character (\(8\text{ bits}\) for Extended ASCII):
\(\text{File size in bits} = 12 \times 8 = 96\text{ bits}\)
Step 3: Convert to bytes (divide bits by \(8\)):
\(\text{File size in bytes} = \frac{96}{8} = 12\text{ bytes}\)
Notice a handy rule of thumb: In \(8\)-bit Extended ASCII, \(1\text{ character} = 1\text{ byte}\). So \(100\text{ characters} = 800\text{ bits} = 100\text{ bytes}\).
Worked Example 2: \(16\)-bit Unicode
What if a text file containing \(100\text{ characters}\) is saved using a \(16\)-bit Unicode encoding?
• \(\text{File size in bits} = 100 \times 16 = 1,600\text{ bits}\)
• \(\text{File size in bytes} = \frac{1,600}{8} = 200\text{ bytes}\)
Because each character uses \(16\text{ bits}\) (\(2\text{ bytes}\)), the file uses twice as much storage as an \(8\)-bit ASCII file.
Key Takeaway: Text file size equals the character count multiplied by bit depth. Never forget to count spaces and punctuation marks!
---5. Common Pitfalls & Misconceptions
Watch out for these common traps when answering questions on digital text representation:
Mistake 1: Forgetting that spaces and punctuation take up storage
Correction: Spaces, commas, question marks, and line breaks are all characters! Each space requires its own character code and binary storage just like a letter.
Mistake 2: Confusing the number \(7\) with the text character '7'
Correction: When stored as a raw numerical value in binary, the denary number \(7\) is \(00000111\). However, the text character '7' typed on a keyboard has the ASCII character code of denary \(55\) (binary \(00110111\)).
Mistake 3: Thinking 'A' and 'a' share the same binary code
Correction: Computers treat uppercase and lowercase letters as completely separate characters with different codes ('A' is \(65\); 'a' is \(97\)).
Mistake 4: Believing ASCII and Unicode store font styles, colours, or sizes
Correction: Character sets only encode which letter or symbol is present. Text formatting (such as bold, italic, font style, or font colour) is stored separately by document markup or word-processing software.
Mistake 5: Assuming Unicode only stores alphabetic letters
Correction: Unicode includes mathematical symbols, scientific notation, ancient scripts, directional control markers, and emojis!
6. Quick Chapter Review
Let's check your understanding with this quick summary checklist:
✔ Binary Nature of Computers: Computers only process electrical \(0\)s and \(1\)s.
✔ Character Set: A standardized table linking every character to a unique numeric code.
✔ \(7\)-bit ASCII: Stores \(2^7 = 128\) characters (English letters, digits, basic punctuation, control codes).
✔ \(8\)-bit Extended ASCII: Stores \(2^8 = 256\) characters (adds European accents and extra symbols).
✔ ASCII Values to Remember: 'A' \(= 65\), 'a' \(= 97\), '0' \(= 48\). (Uppercase to lowercase: add \(32\)).
✔ Unicode: Supports up to \(16\) or \(32\) bits (billions of characters) for all world languages and emojis; backward compatible with ASCII.
✔ File Size: \(\text{Size in bits} = \text{number of characters} \times \text{bits per character}\).