Character Encoding
Character Encoding
Character encoding is a system that assigns a unique binary number to every character (letters, digits, symbols) so computers can store and process text.
---
Why Encoding Is Needed
Computers only understand binary (0s and 1s). To store the letter "A", the computer needs a numeric code that both the sender and receiver agree on. Without a standard encoding, text would appear as random symbols.
---
ASCII (American Standard Code for Information Interchange)
ASCII was one of the first character encoding standards, developed in the 1960s.
Key Facts
| Property | Detail |
|---|---|
| Bits per character | 7 bits (extended ASCII uses 8) |
| Total characters | 128 (7-bit) or 256 (8-bit extended) |
| Includes | Uppercase A–Z, lowercase a–z, digits 0–9, punctuation, control codes |
| Does not include | Characters from non-Latin alphabets (Chinese, Arabic, etc.) |
ASCII Code Table (Key Values)
| Character | Decimal | Binary (7-bit) |
|---|---|---|
| Space | 32 | 0100000 |
| 0 | 48 | 0110000 |
| 9 | 57 | 0111001 |
| A | 65 | 1000001 |
| Z | 90 | 1011010 |
| a | 97 | 1100001 |
| z | 122 | 1111010 |
Important Patterns
- Uppercase letters start at 65 (A) and go to 90 (Z)
- Lowercase letters start at 97 (a) and go to 122 (z)
- The difference between uppercase and lowercase is always 32 (e.g. A=65, a=97)
- Digits 0–9 start at 48
---
Worked Conversions
Example 1: Character to Binary
Convert "C" to binary:
1. "C" = ASCII code 67
2. 67 in binary: 64 + 2 + 1 = 1000011
Example 2: Binary to Character
Convert 1001000 to a character:
1. 1001000 = 64 + 8 = 72
2. ASCII 72 = "H"
Example 3: Encode a Word
Encode "Hi" in 7-bit ASCII:
- "H" = 72 = 1001000
- "i" = 105 = 1101001
- Result: 1001000 1101001
Calculating File Size with ASCII
A text file containing "Hello" (5 characters) in 8-bit ASCII:
- 5 characters × 8 bits = 40 bits = 5 bytes
---
Unicode
Unicode was developed to solve ASCII's limitation of supporting only English characters.
Key Facts
| Property | Detail |
|---|---|
| Bits per character | Variable: UTF-8 (8–32 bits), UTF-16 (16–32 bits), UTF-32 (32 bits) |
| Total characters | Over 143,000 characters |
| Includes | Every language (Chinese, Arabic, Hindi, etc.), emoji, mathematical symbols |
| Backwards compatible | The first 128 Unicode values match ASCII exactly |
UTF-8 (Most Common Encoding)
- Uses 1 to 4 bytes per character
- English characters use 1 byte (same as ASCII)
- Characters from other languages use 2–4 bytes
- This makes it space-efficient for English text
UTF-16 and UTF-32
| Encoding | Bytes per character | Best for |
|---|---|---|
| UTF-8 | 1–4 | Web pages, English-heavy text |
| UTF-16 | 2–4 | Mixed-language text |
| UTF-32 | 4 (fixed) | Fast processing (fixed width) |
---
ASCII vs Unicode Comparison
| Feature | ASCII | Unicode |
|---|---|---|
| Characters | 128 / 256 | 143,000+ |
| Languages | English only | All languages |
| Bits per character | 7 or 8 | 8–32 (varies) |
| File size | Smaller | Larger (for non-English) |
| Emoji support | No | Yes |
| Compatibility | Subset of Unicode | Includes ASCII |
---
How Character Sets Affect File Size
The number of bits per character directly affects storage:
| Scenario | Calculation | Size |
|---|---|---|
| 100 chars in ASCII (8-bit) | 100 × 8 = 800 bits | 100 bytes |
| 100 chars in UTF-8 (English) | 100 × 8 = 800 bits | 100 bytes |
| 100 chars in UTF-16 | 100 × 16 = 1,600 bits | 200 bytes |
| 100 chars in UTF-32 | 100 × 32 = 3,200 bits | 400 bytes |
More bits per character = larger file size but more characters available.
---
Exam Tips
- You must know that ASCII uses 7 bits (128 characters) and Unicode supports all languages
- Be able to convert between characters and their ASCII codes using the table
- Remember: the difference between upper and lowercase in ASCII is 32
- A common calculation question: file size = number of characters × bits per character
- Unicode is backwards compatible with ASCII — the first 128 codes are identical
- Know why Unicode was needed: globalisation required representing characters from all languages and scripts