Text Representation: ASCII & Unicode
Computers store text as numbers. A character such as A, Ә or 中 is assigned a numerical code, and an encoding determines how that code is stored as bytes. This lesson compares ASCII and Unicode and shows how to calculate the storage required by a text fragment.
Learning Objectives
- 11.1.1.7 Compare Unicode and ASCII
- 11.1.1.8 Calculate the number of bytes required to store a text fragment
From Character to Binary
A letter, digit, punctuation mark, symbol, emoji or other textual element.
A collection of characters with numerical codes assigned to them.
A rule for converting character codes into bytes for storage or transmission.
Important terminology
Unicode defines characters and their code points. Encodings such as UTF-8, UTF-16 and UTF-32 specify how Unicode code points are represented as bytes.
ASCII
ASCII (American Standard Code for Information Interchange)
is an early character set designed mainly for English-language text and control characters.
Standard ASCII uses 7 bits, giving 2^7 = 128 possible codes.
| Character | Decimal ASCII | 7-bit binary | Stored in an 8-bit byte |
|---|---|---|---|
A | 65 | 1000001 | 01000001 |
a | 97 | 1100001 | 01100001 |
0 | 48 | 0110000 | 00110000 |
| space | 32 | 0100000 | 00100000 |
“Extended ASCII” is not one universal standard
Standard ASCII is the 7-bit, 128-code set. Many older systems used different 8-bit code pages for additional characters; these are often loosely called “extended ASCII”, but they are not one single universal character set.
Unicode
Unicode assigns each supported character a unique code point,
written in forms such as U+0041 for A or U+04D8 for Ә.
The same Unicode text can then be encoded using UTF-8, UTF-16 or another Unicode encoding.
ASCII compatibility
Standard ASCII characters are included in Unicode. In UTF-8, the first 128 code points use the same byte values as ASCII, so ordinary ASCII text is automatically valid UTF-8.
ASCII vs Unicode
| Feature | ASCII | Unicode |
|---|---|---|
| Character coverage | Small set; mainly English letters, digits, punctuation and control characters | Designed for characters from many writing systems, symbols and emoji |
| Standard size idea | 7-bit standard ASCII: 128 codes | Much larger code space |
| Storage | Commonly stored as one byte per ASCII character | Depends on the Unicode encoding and the character |
| Compatibility | ASCII is limited but simple | Includes all standard ASCII characters |
| Example limitation / strength | Cannot directly represent characters such as Ә, 中 or 🙂 | Can assign code points to these characters |
Exam-style comparison answer
Difference 1: ASCII has a much smaller character set, while Unicode supports characters from many languages and symbol systems.
Difference 2: ASCII has a fixed 7-bit standard code set and is commonly stored in one byte per character, while Unicode can use encodings such as UTF-8 or UTF-16 that may require multiple bytes for some characters.
Calculating Text Storage
Case 1 — Fixed number of bits per character
size in bits
= number of characters × bits per character
size in bytes
= size in bits ÷ 81 250 characters at 8 bits per character
250 × 8
= 2000 bits
2000 ÷ 8
= 250 bytes2 120 characters at 16 bits per character
120 × 16
= 1920 bits
1920 ÷ 8
= 240 bytesCase 2 — UTF-8 variable-length text
3 AӘ中🙂 in UTF-8
A → 1 byte
Ә → 2 bytes
中 → 3 bytes
🙂 → 4 bytes
Total
= 1 + 2 + 3 + 4
= 10 bytesExam rule
Do not invent a fixed “Unicode bytes per character” value. Use the encoding and bit/byte information stated in the question. If the question uses a simplified model such as “16 bits per character”, calculate with that model.
Character count alone may not determine UTF-8 size
Four ASCII characters need 4 bytes in UTF-8, but four non-ASCII characters can require more. You need to know the actual characters or their byte lengths.
Interactive Labs
1. ASCII or Unicode?
2. Fixed-Width Text Size Calculator
3. UTF-8 Byte Inspector
4. Storage Reasoning
Common Pitfalls
“Unicode = 16 bits per character”
This is not generally correct. Unicode is a character standard; encodings such as UTF-8 and UTF-16 determine the stored bytes.
“ASCII = only letters”
ASCII also contains digits, punctuation, control characters and symbols.
Forgetting bits → bytes
If a calculation produces bits, divide by 8 to obtain bytes.
Counting characters but ignoring the encoding
For variable-length encodings such as UTF-8, different characters can use different numbers of bytes.
Graded Tasks
State what ASCII stands for and how many codes are available in standard 7-bit ASCII.
Explain two differences between ASCII and Unicode.
Explain the difference between a Unicode code point and a Unicode encoding such as UTF-8.
A text fragment contains 450 characters stored at 8 bits per character. Calculate its size in bytes.
A text fragment contains 300 characters stored at 16 bits per character. Calculate its size in bytes.
Explain why the same number of characters can require different amounts of storage in UTF-8.
Using the byte lengths A = 1, Ә = 2, 中 = 3 and 🙂 = 4, calculate the UTF-8 size of AӘ中🙂A.
A school needs to store Kazakh, English and emoji in student messages. Justify why Unicode is more suitable than ASCII.
Exam Practice
Q1: State two differences between ASCII and Unicode. [2]
Reveal marking points
Q2: A text fragment contains 180 characters. It is stored using 8 bits per character. Calculate the storage required in bytes. [2]
Reveal marking points
Q3: A system stores 75 characters using 16 bits per character. Calculate the size in bytes. [2]
Reveal marking points
Q4: Explain why the number of characters alone may be insufficient to calculate the size of a Unicode text fragment stored using UTF-8. [2]