Back to Hub

Character Sets: ASCII vs Unicode

Computers cannot understand human letters directly; they only process binary numbers. A character set maps every character to a unique binary code, expanding from 7-bit ASCII for English text to multi-byte Unicode for all world languages and emojis.

Interactive Message Encoder

Try typing letters, numbers, or emojis (e.g. 'Hello 👾')
Encoded Binary Stream Output: 8 Characters • 10 Bytes (80 bits)
01001000 01100101 01101100 01101100 01101111 00100000 11110000 10011111 10011001 10101110
Bytes separated by spaces for clarity. Hardware stores this as a continuous bitstream. Hex: 48 65 6C 6C 6F 20 F0 9F 99 BE
Character Breakdown:
ASCII Discovery

The ASCII "+32" Case-Flipper (The Bit 5 Secret)

How computers flip case with a single bit

Ever wondered why 'A' is 65 and 'a' is 97? The difference is exactly 32 (97 − 65 = 32). In binary, 32 is a single bit power of two ($2^5$). To change any uppercase English letter to lowercase, a computer doesn't search a dictionary — it simply sets Bit 5 to 1!

UPPERCASE: 'A'
Denary: 65
Bit 5 = 0 (OFF)
lowercase: 'a'
Denary: 97 (65 + 32)
Bit 5 = 1 (ON → +32 added!)
Sequential Offsets

Character Offset Calculator

"If 'A' is 65, what is the code for..."

Character sets like ASCII are arranged in strict alphabetical order. You don't need to memorize every ASCII number — just calculate the alphabetical distance!

'A' = 65 →
Storage Impact

Storage Trade-Off: ASCII vs Unicode

Why we don't just use 32-bit for everything

Unicode solves the language barrier, but if every English letter took 4 bytes (UTF-32), file sizes would quadruple! See how your typed message compares across standards:

ASCII (American Standard Code)

7-bit / 8-bit
  • 7-bit ASCII: Represents 27 = 128 characters (0 to 127). Covers English uppercase, lowercase, punctuation, and control codes.
  • Extended ASCII: Uses 8 bits (28 = 256 characters). Adds European accented characters like é, ñ, ü.
  • Limitation: Cannot represent Chinese, Arabic, Hindi, Cyrillic, or emojis!

Unicode (Universal Encoding)

16-bit to 32-bit
  • Universal: Designed to represent every writing system in the world plus thousands of mathematical symbols and emojis.
  • Variable Length (UTF-8): Uses 1 to 4 bytes per character.
  • Backwards Compatible: The first 128 Unicode characters are identical to standard ASCII (e.g. 'A' is code 65 in both!).

Huffman Coding & Lossless Compression

Huffman coding reduces file sizes without losing data by giving frequent characters shorter binary codes and rarer characters longer ones. Because the original data can be reconstructed perfectly, it is known as lossless compression.

Why Huffman Coding Works

Standard ASCII allocates a fixed 8 bits (1 byte) for every character, whether it's common like 'E' or rare like 'Z'. Huffman coding is a brilliant lossless algorithm that analyses character frequencies and builds a binary tree. The most frequent characters sit near the top of the tree and receive short binary codes (1–2 bits), saving up to 70% of storage!

Frequency First: Count how often each character appears. Rare letters get combined first into branches.
Branch Convention: Go left = 0, Go right = 1. Tracing from root to leaf gives the character's code.
Prefix Rule: No code is a prefix of any other code. A continuous stream can be uniquely decoded without any spaces!

1. Input Text & Presets

6 Characters
Quick Presets:

2. Binary Huffman Tree

Left = 0 • Right = 1
Character Frequencies:
Hover over any leaf node or table row to trace its branch path from the root!

3. Generated Codebook & Stats

Saved 68%
Char Count ASCII Bits Huffman Code Huffman Bits
Storage Comparison: 9 bits vs 48 bits
STANDARD ASCII: 8 chars × 8 = 64 bits
HUFFMAN COMPRESSED: Total = 20 bits
Encoded Binary Bitstream:

GCSE Exam Questions on Huffman Coding

Guaranteed Exam Topic
Question 1 • 2 Marks

Explain why Huffman coding is classified as a lossless compression technique rather than a lossy compression technique.

View Model Answer • 2 Marks
• Mark 1: No original character data is permanently discarded or lost during compression.
• Mark 2: Decompressing the binary stream using the Huffman tree perfectly reconstructs the original uncompressed text bit-for-bit.
Question 2 • 3 Marks

The word "BANANA" is compressed using Huffman coding into codes: A = 0, N = 10, B = 11. Calculate the total bits saved compared to standard 8-bit ASCII.

View Model Answer • 3 Marks
• Mark 1 (ASCII): 6 letters × 8 bits = 48 bits.
• Mark 2 (Huffman): B(2) + A(1) + N(2) + A(1) + N(2) + A(1) = 2 + 1 + 2 + 1 + 2 + 1 = 9 bits.
• Mark 3 (Saved): 48 − 9 = 39 bits saved (81.25% reduction!).
Question 3 • 2 Marks (Exam Trap)

Why must the Huffman tree or frequency table be saved inside the compressed file header along with the binary stream?

View Model Answer • 2 Marks
• Mark 1: Huffman codes are dynamic and unique to every individual document based on its letter frequencies.
• Mark 2: Without the frequency table / tree dictionary in the header, the receiving computer has no translation key to decode which bits belong to which characters.

Character Encoding & Compression Revision

High-yield exam notes, formula cheat-sheets, common pitfalls, and mark-scheme rules for AQA GCSE Computer Science Paper 2 (§3.3.2).

1. Character Sets Overview

Core Concept

A character set is a defined list of characters recognized by a computer hardware/software system, where each character is assigned a unique binary code.

  • Standard ASCII: 7 bits per character = 128 codes (0 to 127). English alphabet, digits 0–9, punctuation, and control symbols.
  • Extended ASCII: 8 bits (1 byte) = 256 codes (0 to 255). Adds European accented characters.
  • Unicode: 16 to 32 bits (typically UTF-8, which uses 1 to 4 bytes). Represents global alphabets (Chinese, Cyrillic, Arabic) and emojis.

2. Essential ASCII Exam Facts

AQA Traps
  • 'A' is 65 (binary: 0100 0001)
  • 'a' is 97 (binary: 0110 0001)
  • '0' (digit zero) is 48 (binary: 0011 0000)
  • Space (' ') is 32 (binary: 0010 0000)
  • Case Difference: Lowercase letters are always 32 higher than uppercase letters (setting Bit 5 to 1).

3. Text File Size Formula

Formula
File Size (bits) = Number of characters × Bits per character

Example: A document containing 500 characters saved in 8-bit ASCII requires:
500 × 8 = 4,000 bits = 500 bytes.

4. Compression: Lossless vs Lossy

Exam Rule
  • Text and code MUST use lossless compression: If even 1 bit is changed or removed from a program or text file, the code will corrupt or execute erroneously.
  • Huffman Coding and RLE are lossless: They compress data by optimizing how repetition or frequency is encoded without discarding any original information.