🔒
Pro Content
Subscribe to access all 69 OCR H446 A Level lessons.
£7.99/month
or £59/year
Subscribe now →
🔒 Pro · Component 1 · 1.4.1 Data Types
1.4.1d Character Encoding: ASCII and Unicode
OCR H446 · A Level Computer Science · ~10 min read
Notes
Video
Slides
Worksheet
Quiz

Why Character Encoding?

Computers can only store binary numbers. To represent text, we need a character encoding — a standard mapping that assigns a unique binary code to each character (letter, digit, symbol). Without a shared standard, a file written on one computer would be unreadable on another.

ASCII — American Standard Code for Information Interchange

ASCII was the first widely adopted character encoding standard:

  • 7-bit ASCII: uses 7 bits per character → 2⁷ = 128 characters (code points 0–127)
  • Extended ASCII: uses 8 bits → 2⁸ = 256 characters (adds accented letters, line-drawing characters etc.)
  • Represents: uppercase A–Z (65–90), lowercase a–z (97–122), digits 0–9 (48–57), punctuation, control characters (0–31)
CharacterASCII (decimal)Binary (7-bit)
'A'65100 0001
'B'66100 0010
'Z'90101 1010
'a'97110 0001
'z'122111 1010
'0'48011 0000
'9'57011 1001
Space32010 0000

Key pattern: 'A'=65, 'a'=97, difference = 32. To convert uppercase to lowercase: add 32. To convert lowercase to uppercase: subtract 32. Equivalently, toggling bit 5 (value 32) switches case.

Limitations of ASCII: only covers English characters. Cannot represent Chinese, Arabic, Greek, emoji, or most world scripts. This led to the development of Unicode.

Unicode

Unicode is a universal character encoding standard designed to represent every character in every language in the world:

  • Covers over 1,000,000 code points (currently around 140,000 characters assigned)
  • Code points are written as U+XXXX (e.g. U+0041 = 'A', U+1F600 = 😀)
  • Backwards compatible with ASCII — the first 128 Unicode code points match ASCII exactly
  • Supports emoji, mathematical symbols, historical scripts, and all major world languages

Unicode Encodings: UTF-8, UTF-16, UTF-32

Unicode defines code points (abstract numbers), but these must be encoded into bytes for storage. The main encodings are:

EncodingBits per characterKey features
UTF-8Variable: 8–32 bits (1–4 bytes)ASCII characters use 1 byte (same as ASCII). Most common on the web. Efficient for English text.
UTF-16Variable: 16 or 32 bits (2–4 bytes)Common in Windows and Java. BMP characters use 2 bytes; surrogate pairs for others.
UTF-32Fixed: 32 bits (4 bytes)Simple fixed-width encoding. Each character always uses 4 bytes. Wastes space for English text.

Why UTF-8 is Dominant

  • ASCII-compatible: existing ASCII text is valid UTF-8 without modification
  • Space-efficient for Western languages: most Latin characters are 1 byte
  • No byte-order issues (unlike UTF-16/32 which have endianness concerns)
  • Used by over 97% of web pages

Character Encoding and Storage

The file size of a text file depends on the encoding:

  • A 1000-character ASCII file = 1000 bytes (1 byte per character)
  • The same file in UTF-8 = 1000 bytes (ASCII chars = 1 byte each)
  • The same file in UTF-32 = 4000 bytes (4 bytes per character always)
Exam tip: Key ASCII values to memorise: 'A'=65, 'a'=97, '0'=48, Space=32. The difference between uppercase and lowercase is always 32 (bit 5 = 32). The character '0' is code 48, not code 0 — the digit 0 as a character is NOT the same as the null control character (code 0).
Exam tip: ASCII uses 7 bits (128 characters). Extended ASCII uses 8 bits (256 characters). Unicode uses variable-length encoding (UTF-8 is most common — 1 to 4 bytes per character). Unicode is backwards-compatible with ASCII — the first 128 code points are identical.
⚠ Common Mistakes
  • Confusing the character '0' (ASCII 48) with the null character (ASCII 0) — '0' is a printable character, ASCII 0 is a control code.
  • Saying Unicode uses "2 bytes per character" — this is only true for UTF-16 Basic Multilingual Plane characters. UTF-8 is variable (1–4 bytes), UTF-32 is always 4 bytes.
  • Forgetting that ASCII only uses 7 bits (not 8). Extended ASCII adds an extra bit for 256 characters, but standard ASCII is 7-bit.
✓ Notes completed!
Video coming soon
Click to advance · Arrow keys also work
Click slide or press arrow keys to navigate

Worksheet — 1.4.1d Character Encoding: ASCII and Unicode

8 questions · 20 marks · instantly marked

Q1How many different characters can standard 7-bit ASCII represent? Explain why.[2 marks]
✓ Mark scheme
7-bit ASCII can represent 2⁷ = 128 characters [1]. With 7 bits, there are 2⁷ = 128 possible unique bit patterns (0000000 to 1111111), one for each character [1].
Q2The ASCII code for 'A' is 65. What is the ASCII code for 'H'? Show your reasoning.[2 marks]
✓ Mark scheme
ASCII codes for letters are consecutive: A=65, B=66, C=67, D=68, E=69, F=70, G=71, H=72 [1]. 'H' is the 8th letter, so 65 + 7 = 72 [1].
Q3Explain why ASCII is insufficient for a modern global application, and why Unicode was developed.[3 marks]
✓ Mark scheme
ASCII only represents 128 characters [1], which is enough for English but cannot represent characters from other languages such as Chinese, Arabic, Japanese, Greek etc. [1]. Unicode was developed to provide a universal encoding that covers every character in every language in the world, allowing global software interoperability [1].
Q4Explain the difference between a Unicode code point and a Unicode encoding such as UTF-8.[3 marks]
✓ Mark scheme
A Unicode code point is an abstract number assigned to a character (e.g. U+0041 = 'A'), telling you which character it is — it is not yet a sequence of bytes [1]. A Unicode encoding (such as UTF-8) specifies how to convert code points into actual bytes for storage or transmission [1]. UTF-8 uses 1–4 bytes per character depending on the code point value — ASCII code points use 1 byte, higher code points use more [1].
Q5A text file contains the word "HELLO" (5 characters). Calculate its size in bytes when stored as (a) ASCII, (b) UTF-32.[2 marks]
✓ Mark scheme
(a) ASCII: 1 byte per character × 5 = 5 bytes [1]. (b) UTF-32: 4 bytes per character × 5 = 20 bytes [1].
Q6The ASCII code for lowercase 'a' is 97. Without looking it up, explain how you can find the ASCII code for uppercase 'A' and give the value.[2 marks]
✓ Mark scheme
The difference between the ASCII code for any lowercase letter and its uppercase equivalent is always 32 [1]. Therefore 'A' = 97 − 32 = 65 [1]. (Equivalently: bit 5 of the binary code distinguishes case — flipping bit 5 changes case.)
Q7Explain why UTF-8 has become the dominant encoding on the internet, while UTF-32 is rarely used for web content.[4 marks]
✓ Mark scheme
UTF-8 is dominant because: it is backwards-compatible with ASCII — any valid ASCII file is also valid UTF-8, so existing software and content does not need modification [1]; it is space-efficient for English/Latin text — common characters use only 1 byte, reducing file size and transmission time [1]; it has no byte-order (endianness) ambiguity [1]. UTF-32 is rarely used for web because every character uses 4 bytes regardless of whether it's a simple ASCII character — English text becomes 4× larger than necessary, wasting storage and bandwidth [1].
Q8Decode the following ASCII codes to find the hidden word: 67, 79, 77, 80, 85, 84, 69, 82. ('A'=65, 'a'=97, '0'=48)[2 marks]
✓ Mark scheme
67−65=C, 79−65=O, 77−65=M, 80−65=15=P, 85−65=20=U, 84−65=19=T, 69−65=4=E, 82−65=17=R. Correct: C(67), O(79), M(77), P(80), U(85), T(84), E(69), R(82) = COMPUTER [2 — 1 for correct method, 1 for correct answer].
Topic Quiz
1 of 15
You scored
out of 15
🎯

Mini Test — 1.4.1d ASCII & Unicode

  • 10 questions · 10 marks · 10 minutes
  • 5 MCQ + 5 short answer
Card 1 of 15
Click to reveal
🎉
Complete!
TermDefinition
← 1.4.1c Floating Point 1.4.1 Data Types Next: 1.4.2a Data Structures →