UNICODE ENCODING FORMATS: UTF-8, UTF-16,
UTF-32
1. Introduction
Unicode (Universal Character Code) is a standard that assigns a unique number to every character
used in human languages and symbols. To store these numbers in computers, Unicode uses
encoding formats called UTF-8, UTF-16, and UTF-32.
2. UTF-8
UTF-8 is a variable-length encoding that uses 1 to 4 bytes. It is backward compatible with ASCII
and is the most widely used encoding on the internet.
3. UTF-16
UTF-16 uses 16 bits (2 bytes) per unit. It can represent 65,536 characters directly. Characters
beyond this range are represented using surrogate pairs (two 16-bit units).
4. UTF-32
UTF-32 uses 32 bits (4 bytes) for every character. It can represent over 4.29 billion characters and
uses fixed-length encoding, making it simple but memory-inefficient.
5. Flowchart: Choosing Unicode Encoding
Start
|
v
Is storage efficiency important?
|
+-- Yes --> Use UTF-8
|
No
|
v
Is fixed-length encoding required?
|
+-- Yes --> Use UTF-32
|
No
|
v
Use UTF-16
6. Example Exam Questions and Answers
Q1: What is Unicode?
Answer: Unicode is a universal standard that provides a unique code for every character in all languages.
Q2: How many characters can UTF-16 represent using one unit?
Answer: UTF-16 can represent 65,536 characters using one 16-bit unit.
Q3: Why is UTF-8 widely used?
Answer: UTF-8 is space-efficient, backward compatible with ASCII, and ideal for web applications.
Q4: State one advantage and one disadvantage of UTF-32.
Answer: Advantage – fixed-length encoding makes processing simple.
Disadvantage – wastes a lot of memory.