# Text Representation: ASCII & Unicode

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 1: Data Representation
- **Estimated Duration:** 15 minutes
- **Access:** Open Theory + Free Practice

---

## Theory & Conceptual Background

A **character set** assigns a numeric code to each supported character. The computer stores those codes in binary. A character might be a letter, digit, punctuation mark or control character such as a line break.

## ASCII and Unicode

ASCII uses 7-bit codes, giving 128 possible values. For example, uppercase A has code 65, represented as 1000001. A stored byte may include a leading zero: 01000001. Lowercase and uppercase letters have different codes.

An 8-bit code provides 256 possible values. Different extended-ASCII code pages use the extra values for different scripts or symbols. One may support Cyrillic, another Arabic; one 256-character set cannot represent all languages together. Sender and receiver need to agree on the character encoding or the text may display incorrectly.

Unicode assigns codes for a much larger range of languages and symbols. It enables multilingual documents to use a common character standard. It is not a promise that every character occupies the same number of bytes.

## Worked example

If a simplified encoding uses one byte for every character in a 240-character message, its text takes 240 bytes, excluding headers. If each of those particular characters takes two bytes, the same message takes 480 bytes. Use the encoding assumption given in the question, rather than assuming all Unicode text doubles in size.

## Optional detail: encodings

UTF-8 uses one to four bytes per Unicode code point and preserves ASCII values in its one-byte range. UTF-16 uses one or two 16-bit code units per code point. For 500 English ASCII-range characters encoded as UTF-16 without a byte-order mark or header, the calculation is 500 × 2 = 1000 bytes.

## Explain it yourself

A museum needs labels in several different writing systems. Explain why Unicode is more suitable than a single 8-bit code page. Connect its larger repertoire to the museum's need; do not claim every Unicode character occupies two bytes.

## Written practice and self-review

An international e-commerce company updates its database text encoding from ASCII to Unicode UTF-8. State one major benefit of this change for global customers. Explain one technical trade-off regarding data storage capacity and network transmission bandwidth.

Write an explanation before checking the theory. Check that each claim answers the question, uses the correct concept and explains why it applies. Discuss uncertain points with a teacher. The structured exercise below checks specific facts; it does not automatically mark this explanation.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Concept Check: Apply the distinction (Fill in blank, 30 XP)

**Instructions:**
Work out each answer before submitting. Number of possible seven-bit codes: Does one eight-bit code page represent all writing systems together: yes or no? Bytes for 120 characters if each uses two bytes:


**Starter Code:**
```text
{"prompt":"Concept Check: Apply the distinction","template":"1. Number of possible seven-bit codes: [blank_1]\n2. Does one eight-bit code page represent all writing systems together: yes or no? [blank_2]\n3. Bytes for 120 characters if each uses two bytes: [blank_3]","blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}],"word_bank":["128","no","240","256","64","yes","120","480"]}
```


### Exercise 2: Exam-Style Question: Calculate Text File Storage Sizes (Fill in blank, 35 XP)

**Instructions:**
A text document contains 500 ASCII-range English characters with no formatting, byte-order mark or headers.

1. Calculate the file size in bytes if the document is stored using Standard ASCII (1 byte per character): [blank_1] bytes.
2. Calculate the file size in bytes if the document is stored using Unicode UTF-16 (2 bytes for each of these particular characters): [blank_2] bytes.
3. Calculate the difference in storage in bytes: [blank_3] bytes.


**Starter Code:**
```text
{"prompt":"Complete the storage calculations:","template":"1. ASCII size: [blank_1] bytes\n2. UTF-16 size: [blank_2] bytes\n3. Difference: [blank_3] bytes","word_bank":["500","1000","250","1500","2000","750"],"blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}]}
```

**Autotest Expectations:**
- **ASCII size calculated correctly**: `text_exact` -> Expected: `500`
- **UTF-16 size calculated correctly**: `text_exact` -> Expected: `1000`
- **Storage difference calculated correctly**: `text_exact` -> Expected: `500`

### Exercise 3: Application: Encoding size (Fill in blank, 30 XP)

**Instructions:**
Work out each answer before submitting. A stated one-byte encoding stores 360 characters. Bytes required: The same characters each need two bytes in another stated encoding. Bytes required: Does Unicode require every character to occupy exactly two bytes: yes or no?


**Starter Code:**
```text
{"prompt":"Application: Encoding size","template":"1. A stated one-byte encoding stores 360 characters. Bytes required: [blank_1]\n2. The same characters each need two bytes in another stated encoding. Bytes required: [blank_2]\n3. Does Unicode require every character to occupy exactly two bytes: yes or no? [blank_3]","blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}],"word_bank":["360","720","no","yes","180","1440"]}
```


