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!
Character sets like ASCII are arranged in strict alphabetical order. You don't need to memorize every ASCII number — just calculate the alphabetical distance!
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:
- 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!
- 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!).
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!
0, Go right = 1. Tracing from root to leaf gives the character's code.
| Char | Count | ASCII Bits | Huffman Code | Huffman Bits |
|---|
Explain why Huffman coding is classified as a lossless compression technique rather than a lossy compression technique.
View Model Answer • 2 Marks
• Mark 2: Decompressing the binary stream using the Huffman tree perfectly reconstructs the original uncompressed text bit-for-bit.
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 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!).
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 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.
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.
- '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).
Example: A document containing 500 characters saved in 8-bit ASCII requires:
500 × 8 = 4,000 bits = 500 bytes.
- 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.