A computer understands only 0s and 1s, yet it displays your name, calculates your marks and shows colourful images. Data Representation explains how: this chapter covers the decimal, binary, octal and hexadecimal number systems, conversions between them, and how characters and strings are encoded using ASCII, ISCII and Unicode (UTF-8 and UTF-32).
Practise every conversion by hand first, then verify with a calculator. Start with Binary-Decimal and Decimal-Binary conversions, because the other conversions build on them.
2.1 ๐ Introduction
Computers are essentially just VERY fast switches โ millions of tiny electronic switches that can only be in TWO states: ON or OFF.
graph LR
ON["โก Switch ON\n= 1"]
OFF["โซ Switch OFF\n= 0"]
BINARY["๐ข Combined together:\nBINARY NUMBERS\n(0s and 1s)"]
ON --> BINARY
OFF --> BINARY
style ON fill:#4CAF50,color:#fff
style OFF fill:#9E9E9E,color:#fff
style BINARY fill:#2196F3,color:#fff
Think of it this way: A light switch can only be ON or OFF โ there's no "half on." Computers work EXACTLY like this, using millions of switches (transistors) to represent EVERY piece of data โ numbers, letters, images, sounds โ all as combinations of 0s and 1s!
Why do we need different Number Systems?
Humans
We naturally think in Decimal (Base 10) โ we have 10 fingers!
0123456789Computers
Internally, they think ONLY in Binary (Base 2) โ ON/OFF switches
01Programmers
Often use Octal/Hexadecimal as a SHORTHAND for binary
Easier for humans to read long binary strings2.2 ๐ข Digital Number Systems
A Number System is a way of representing numbers using a specific set of symbols (digits) and a BASE (also called radix) โ the total count of unique digits used.
graph TD
NS["๐ข NUMBER SYSTEMS"]
D["๐ Decimal\nBase 10\n(0-9)"]
B["๐ต Binary\nBase 2\n(0-1)"]
O["๐ Octal\nBase 8\n(0-7)"]
H["๐ฃ Hexadecimal\nBase 16\n(0-9, A-F)"]
NS --> D
NS --> B
NS --> O
NS --> H
style D fill:#4CAF50,color:#fff
style B fill:#2196F3,color:#fff
style O fill:#FF9800,color:#fff
style H fill:#9C27B0,color:#fff
2.2.1 Decimal (Denary) Number System (Base 10) ๐
The number system we humans use EVERY DAY โ uses 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Number: 2 5 3
Position: 100s 10s 1s
Value: (2ร100) + (5ร10) + (3ร1) = 253
Positional Value System:
253 (base 10) = 2ร10ยฒ + 5ร10ยน + 3ร10โฐ
= 2ร100 + 5ร10 + 3ร1
= 200 + 50 + 3 = 253
Key Concept: In ANY number system, each digit's position represents a POWER of the base. This "positional value" concept is the foundation for understanding ALL number systems!
2.2.2 Binary Number System (Base 2) ๐ต
Uses only 2 digits: 0 and 1 โ the LANGUAGE computers actually speak internally!
Binary: 1 0 1 1
Position: 2ยณ 2ยฒ 2ยน 2โฐ
Value: (1ร8) + (0ร4) + (1ร2) + (1ร1) = 11 (decimal)
| Position (Power of 2) | 2ยณ=8 | 2ยฒ=4 | 2ยน=2 | 2โฐ=1 |
|---|---|---|---|---|
| Binary Digit | 1 | 0 | 1 | 1 |
| Value | 8 | 0 | 2 | 1 |
8 + 0 + 2 + 1 = 11 โ So (1011)โ = (11)โโ
Each binary digit is called a BIT (Binary Digit). 8 bits together = 1 BYTE!
2.2.3 Octal Number System (Base 8) ๐
Uses 8 digits: 0, 1, 2, 3, 4, 5, 6, 7.
Octal: 3 7 2
Position: 8ยฒ 8ยน 8โฐ
Value: (3ร64) + (7ร8) + (2ร1) = 192+56+2 = 250 (decimal)
Octal was popular in early computing as a SHORTHAND for binary โ since 8 = 2ยณ, exactly 3 binary digits map to ONE octal digit!
2.2.4 Hexadecimal Number System (Base 16) ๐ฃ
Uses 16 digits: 0-9, then A, B, C, D, E, F (where A=10, B=11, C=12, D=13, E=14, F=15).
| Hex Digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Decimal Value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Hex: 2 A
Position: 16ยน 16โฐ
Value: (2ร16) + (Aร1) = (2ร16) + (10ร1) = 32+10 = 42 (decimal)
Hexadecimal is HUGELY popular in programming โ since 16 = 2โด, exactly 4 binary digits map to ONE hex digit! This makes hex a super-compact way to write binary. You've SEEN hex before: color codes like
#FF5733in CSS/web design are hexadecimal!
All Four Number Systems โ Quick Reference:
| System | Base | Digits Used | Example |
|---|---|---|---|
| Decimal | 10 | 0-9 | 253 |
| Binary | 2 | 0-1 | 1011 |
| Octal | 8 | 0-7 | 372 |
| Hexadecimal | 16 | 0-9, A-F | 2A |
"What is the base of Binary, Octal, and Hexadecimal number systems?" โ 1-mark question. Answer: Binary = 2, Octal = 8, Hexadecimal = 16, Decimal = 10
2.3 ๐ Number Conversions
This section works through every conversion, step by step.
graph TD
DEC["๐ Decimal"]
BIN["๐ต Binary"]
OCT["๐ Octal"]
HEX["๐ฃ Hexadecimal"]
DEC <--> BIN
DEC <--> OCT
DEC <--> HEX
BIN <--> OCT
BIN <--> HEX
HEX <--> OCT
style DEC fill:#4CAF50,color:#fff
style BIN fill:#2196F3,color:#fff
style OCT fill:#FF9800,color:#fff
style HEX fill:#9C27B0,color:#fff
2.3.1 Decimal-to-Binary Conversion ๐โก๏ธ๐ต
Method: Repeated Division by 2 โ divide by 2 repeatedly, note the remainders, then read BOTTOM TO TOP.
Example: Convert (25)โโ to Binary
25 รท 2 = 12 remainder 1 โ
12 รท 2 = 6 remainder 0 โ
6 รท 2 = 3 remainder 0 โ
3 รท 2 = 1 remainder 1 โ
1 รท 2 = 0 remainder 1 โ (Read bottom to top!)
Answer: (25)โโ = (11001)โ
graph TD
A["25 รท 2 = 12 R 1"]
B["12 รท 2 = 6 R 0"]
C["6 รท 2 = 3 R 0"]
D["3 รท 2 = 1 R 1"]
E["1 รท 2 = 0 R 1"]
F["Read UPWARDS:\n1-1-0-0-1 = 11001"]
A --> B --> C --> D --> E --> F
style F fill:#4CAF50,color:#fff
Students often forget to read the remainders BOTTOM TO TOP. The FIRST remainder you calculate is the LAST digit of your binary answer, not the first!
2.3.2 Binary-to-Decimal Conversion ๐ตโก๏ธ๐
Method: Multiply each digit by its positional power of 2, then ADD.
Example: Convert (11001)โ to Decimal
1 1 0 0 1
2โด 2ยณ 2ยฒ 2ยน 2โฐ
16 8 4 2 1
(1ร16) + (1ร8) + (0ร4) + (0ร2) + (1ร1)
= 16 + 8 + 0 + 0 + 1
= 25
Answer: (11001)โ = (25)โโ โ (Matches our earlier conversion โ good check!)
"Convert (10110)โ to decimal." โ 1-2 mark question. Answer: (1ร16)+(0ร8)+(1ร4)+(1ร2)+(0ร1) = 16+0+4+2+0 = 22
2.3.3 Decimal-to-Octal Conversion ๐โก๏ธ๐
Method: Repeated Division by 8 โ same process as Decimal-to-Binary, but divide by 8!
Example: Convert (100)โโ to Octal
100 รท 8 = 12 remainder 4 โ
12 รท 8 = 1 remainder 4 โ
1 รท 8 = 0 remainder 1 โ (Read bottom to top!)
Answer: (100)โโ = (144)โ
2.3.4 Octal-to-Decimal Conversion ๐ โก๏ธ๐
Method: Multiply each digit by its positional power of 8, then ADD.
Example: Convert (144)โ to Decimal
1 4 4
8ยฒ 8ยน 8โฐ
64 8 1
(1ร64) + (4ร8) + (4ร1) = 64 + 32 + 4 = 100
Answer: (144)โ = (100)โโ โ
2.3.5 Octal-to-Binary Conversion ๐ โก๏ธ๐ต
Method: Convert EACH octal digit into its 3-bit binary equivalent (since 8 = 2ยณ).
The Octal-Binary Cheat Sheet:
| Octal | Binary (3-bit) |
|---|---|
| 0 | 000 |
| 1 | 001 |
| 2 | 010 |
| 3 | 011 |
| 4 | 100 |
| 5 | 101 |
| 6 | 110 |
| 7 | 111 |
Example: Convert (372)โ to Binary
3 โ 011
7 โ 111
2 โ 010
Combine: 011 111 010
Answer: (372)โ = (011111010)โ
2.3.6 Binary-to-Octal Conversion ๐ตโก๏ธ๐
Method: Group binary digits into sets of 3 (from the RIGHT), then convert each group to its octal digit.
Example: Convert (11111010)โ to Octal
Step 1: Group into 3s from the RIGHT (pad with 0s on the LEFT if needed)
11 111 010 โ 011 111 010
Step 2: Convert each group:
011 = 3
111 = 7
010 = 2
Answer: 372
Answer: (11111010)โ = (372)โ
If the leftmost group doesn't have exactly 3 digits, ADD ZEROS on the LEFT to complete the group. 11 becomes 011 โ this doesn't change the value!
2.3.7 Decimal-to-Hex Conversion ๐โก๏ธ๐ฃ
Method: Repeated Division by 16 โ same process, but divide by 16, and convert remainders 10-15 into A-F!
Example: Convert (250)โโ to Hexadecimal
250 รท 16 = 15 remainder 10 (=A) โ
15 รท 16 = 0 remainder 15 (=F) โ (Read bottom to top!)
Answer: (250)โโ = (FA)โโ
2.3.8 Hex-to-Decimal Conversion ๐ฃโก๏ธ๐
Method: Multiply each digit by its positional power of 16, then ADD.
Example: Convert (FA)โโ to Decimal
F A
16ยน 16โฐ
16 1
(Fร16) + (Aร1) = (15ร16) + (10ร1) = 240 + 10 = 250
Answer: (FA)โโ = (250)โโ โ
2.3.9 Binary-to-Hex Conversion ๐ตโก๏ธ๐ฃ
Method: Group binary digits into sets of 4 (from the RIGHT), then convert each group to its hex digit (since 16 = 2โด).
The Binary-Hex Cheat Sheet:
| Binary (4-bit) | Hex |
|---|---|
| 0000 | 0 |
| 0001 | 1 |
| 0010 | 2 |
| 0011 | 3 |
| 0100 | 4 |
| 0101 | 5 |
| 0110 | 6 |
| 0111 | 7 |
| 1000 | 8 |
| 1001 | 9 |
| 1010 | A |
| 1011 | B |
| 1100 | C |
| 1101 | D |
| 1110 | E |
| 1111 | F |
Example: Convert (11111010)โ to Hex
Step 1: Group into 4s from the RIGHT
1111 1010
Step 2: Convert each group:
1111 = F
1010 = A
Answer: FA
Answer: (11111010)โ = (FA)โโ โ (Matches our earlier work!)
2.3.10 Hex-to-Binary Conversion ๐ฃโก๏ธ๐ต
Method: Convert EACH hex digit into its 4-bit binary equivalent.
Example: Convert (FA)โโ to Binary
F โ 1111
A โ 1010
Combine: 1111 1010
Answer: (FA)โโ = (11111010)โ
Octal โ Binary: group in 3s (since 8=2ยณ) Hex โ Binary: group in 4s (since 16=2โด) Octal โ Hex: ALWAYS convert THROUGH Binary as a middle step โ there's no direct shortcut!
๐ The Complete Conversion Map โ Quick Reference
graph LR
D["Decimal"]
B["Binary"]
O["Octal"]
H["Hex"]
D -->|"รท2 repeatedly"| B
B -->|"ร2โฟ, add"| D
D -->|"รท8 repeatedly"| O
O -->|"ร8โฟ, add"| D
D -->|"รท16 repeatedly"| H
H -->|"ร16โฟ, add"| D
B -->|"group in 3s"| O
O -->|"3-bit each"| B
B -->|"group in 4s"| H
H -->|"4-bit each"| B
style D fill:#4CAF50,color:#fff
style B fill:#2196F3,color:#fff
| Conversion | Method |
|---|---|
| Decimal โ Binary/Octal/Hex | Repeated division by base; read remainders BOTTOM to TOP |
| Binary/Octal/Hex โ Decimal | Multiply each digit by positional power of base, then ADD |
| Binary โ Octal | Group in 3s from the right |
| Binary โ Hex | Group in 4s from the right |
| Octal โ Binary | Expand each digit to 3-bit binary |
| Hex โ Binary | Expand each digit to 4-bit binary |
"Convert (156)โโ to Binary, Octal, and Hexadecimal." โ 3-mark combined-conversion question. Binary: 156รท2 repeatedly โ 10011100 Octal: 156รท8 repeatedly โ 234 Hex: 156รท16 repeatedly โ 9C
2.4 ๐ค Character/String Representation
Numbers are easy โ computers store them directly in binary. But how does a computer store LETTERS, symbols, and text? Through special CODING SCHEMES that assign a unique number to EVERY character!
graph TD
CHAR["๐ค CHARACTER CODES"]
ASCII["๐บ๐ธ ASCII\n(English characters,\n7-8 bits)"]
ISCII["๐ฎ๐ณ ISCII\n(Indian language\ncharacters)"]
UNI["๐ Unicode\n(ALL world languages,\n16+ bits)"]
CHAR --> ASCII
CHAR --> ISCII
CHAR --> UNI
style ASCII fill:#2196F3,color:#fff
style ISCII fill:#FF9800,color:#fff
style UNI fill:#9C27B0,color:#fff
2.4.1 ASCII Code ๐บ๐ธ
ASCII = American Standard Code for Information Interchange. Assigns a unique number (0-127) to English letters, digits, and symbols.
Character 'A' โ ASCII value 65 โ Binary: 01000001
Character 'a' โ ASCII value 97 โ Binary: 01100001
Character '0' โ ASCII value 48 โ Binary: 00110000
Key ASCII Facts:
| Property | Detail |
|---|---|
| Size | 7 bits (values 0-127) or extended to 8 bits (0-255) |
| Covers | English uppercase (A-Z), lowercase (a-z), digits (0-9), symbols |
| 'A' to 'Z' | ASCII values 65 to 90 |
| 'a' to 'z' | ASCII values 97 to 122 |
| '0' to '9' | ASCII values 48 to 57 |
Fun Trick! ๐ง Notice that lowercase letters = uppercase value + 32! 'A' is 65, 'a' is 97 (65+32=97). This is why programmers can easily convert case using simple math!
"What is ASCII? What is the ASCII value range?" โ 2-mark question! Answer: ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns a unique numeric value to English letters, digits, and symbols. Standard ASCII uses 7 bits, giving values from 0 to 127.
2.4.2 ISCII Code ๐ฎ๐ณ
ISCII = Indian Script Code for Information Interchange. Developed specifically to represent characters from INDIAN languages (Hindi, Tamil, Bengali, etc.) that ASCII cannot handle.
Purpose
Represent Indian language scripts digitally
DevanagariTamilTeluguBengali scriptsSize
8-bit encoding
Extends beyond basic ASCII's English-only limitationDeveloped By
Indian government standards body
Specifically for Indian language computing needsAnalogy: If ASCII is a phrasebook that ONLY has English words, ISCII is a SPECIAL phrasebook created specifically for Indian regional languages โ filling the gap ASCII couldn't cover!
2.4.3 Unicode ๐
Unicode is a UNIVERSAL character encoding standard designed to represent EVERY character from EVERY language/script in the WORLD โ plus emojis, symbols, and more!
graph LR
PROB["๐ฉ Problem\nASCII = English only\nISCII = Indian only\nOther countries need\nTHEIR OWN codes too!"]
UNI["๐ Unicode\nONE universal standard\nfor ALL languages\nWORLDWIDE"]
PROB -->|"Solved by"| UNI
style PROB fill:#F44336,color:#fff
style UNI fill:#4CAF50,color:#fff
Why Unicode was needed:
| Old Problem | Unicode's Solution |
|---|---|
| ASCII only covers English | Unicode covers ALL world languages |
| Each country had its OWN separate code | Unicode is ONE universal standard |
| Couldn't mix languages in one document | Unicode allows English + Hindi + Chinese + Emojis together! |
Key Unicode Facts:
| Property | Detail |
|---|---|
| Size | Typically 16 bits (can extend further) โ MUCH larger range than ASCII's 7/8 bits |
| Covers | Every major world language, mathematical symbols, emojis |
| Backward Compatible | The first 128 Unicode values are IDENTICAL to ASCII |
| Used In | Modern websites, apps, programming languages (Python 3 strings are Unicode by default!) |
ASCII vs ISCII vs Unicode โ The Ultimate Comparison:
| Feature | ASCII | ISCII | Unicode |
|---|---|---|---|
| Scope | English only | Indian languages only | ALL world languages |
| Bit Size | 7-8 bits | 8 bits | 16+ bits |
| Character Range | 128-256 | 256 | Over 1 million possible! |
| Modern Usage | Legacy, still a Unicode subset | Rarely used standalone now | โ Universal standard today |
"Differentiate between ASCII and Unicode." โ 2-mark question, asked frequently! Answer: ASCII is a 7-8 bit encoding standard representing ONLY English characters, digits, and symbols (128-256 characters total). Unicode is a UNIVERSAL encoding standard (16+ bits) that can represent characters from EVERY language in the world, including emojis and special symbols โ and importantly, Unicode's first 128 values are backward-compatible with ASCII.
2.4.4 Code Points โ How Unicode Numbers Every Character ๐ข
Unicode gives every character in the world its own unique number, called its code point. A code point is written as U+ followed by the number in hexadecimal.
| Character | What it is | Code point | Decimal value |
|---|---|---|---|
| A | English capital letter A | U+0041 | 65 |
| a | English small letter a | U+0061 | 97 |
| รฉ | Latin small letter e with acute | U+00E9 | 233 |
| โน | Indian Rupee sign | U+20B9 | 8377 |
| เค | Devanagari (Hindi) letter A | U+0905 | 2309 |
| ๐ | Grinning face emoji | U+1F600 | 128512 |
Notice that 'A' is U+0041 = 65 โ exactly its ASCII value. That is what "Unicode is backward compatible with ASCII" means.
Code points run from U+0000 to U+10FFFF, which leaves room for 1,114,112 characters.
But a code point is only a number. To store a character in memory or in a file, that number has to be turned into bytes. The rule that does this is called a Unicode encoding scheme. Your syllabus names two of them: UTF-8 and UTF-32 (UTF = Unicode Transformation Format).
graph LR
CH["๐ค Character\nโน"]
CP["๐ข Code point\nU+20B9"]
U8["๐ข UTF-8\nE2 82 B9\n(3 bytes)"]
U32["๐ต UTF-32\n00 00 20 B9\n(4 bytes)"]
CH --> CP
CP --> U8
CP --> U32
style CP fill:#9C27B0,color:#fff
style U8 fill:#4CAF50,color:#fff
style U32 fill:#2196F3,color:#fff
Analogy: Think of Unicode as one giant roll register for every character in the world โ each character gets its own roll number (the code point). UTF-8 and UTF-32 are two different ways of writing that roll number on a form: UTF-8 uses only as many boxes as the number needs, while UTF-32 always fills in exactly four boxes.
2.4.5 UTF-8 โ The Flexible Encoding ๐ข
UTF-8 is a variable-length encoding. Each character is stored in 1, 2, 3 or 4 bytes (8, 16, 24 or 32 bits), depending on how big its code point is. The "8" tells you that it works in units of 8 bits (1 byte).
| Code point range | Bytes used | Examples of characters |
|---|---|---|
| U+0000 to U+007F | 1 byte | All ASCII characters โ English letters, digits, symbols |
| U+0080 to U+07FF | 2 bytes | Accented letters (รฉ, ยฉ), Greek, Arabic |
| U+0800 to U+FFFF | 3 bytes | Indian scripts (เค , เค), the โน sign, Chinese, Japanese |
| U+10000 to U+10FFFF | 4 bytes | Emojis (๐) and rarely used scripts |
UTF-8 in action:
Character Code point UTF-8 bytes (hex) Bytes used
A U+0041 41 1
รฉ U+00E9 C3 A9 2
โน U+20B9 E2 82 B9 3
เค
U+0905 E0 A4 85 3
๐ U+1F600 F0 9F 98 80 4
Variable Length
Uses 1 to 4 bytes per character depending on the code point
8 to 32 bitsASCII Compatible
Every ASCII character takes 1 byte with exactly the same value as in ASCII
A = 41 hexSaves Space
English text needs only 1 byte per character
CompactMost Widely Used
The standard encoding for web pages and text files and the default for Python 3 source files
Web standardOnly ASCII characters use 8 bits. The โน sign uses 24 bits (3 bytes) and the emoji ๐ uses 32 bits (4 bytes). The 8 is the smallest unit UTF-8 works with.
each byte count has a fixed bit pattern, and the code point's bits fill the x positions:
1 byte : 0xxxxxxx
2 bytes: 110xxxxx 10xxxxxx
3 bytes: 1110xxxx 10xxxxxx 10xxxxxx
4 bytes: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
Example: รฉ = U+00E9 = 000 1110 1001 (11 bits, so 2 bytes are needed). Split it as 00011 and 101001 and fill the pattern: 11000011 10101001 = C3 A9.
2.4.6 UTF-32 โ The Fixed-Size Encoding ๐ต
UTF-32 is a fixed-length encoding. Every character is stored in exactly 4 bytes (32 bits), whatever it is. The code point is simply written as a 32-bit binary number, with leading zeros added in front.
UTF-32 in action:
Character Code point UTF-32 bytes (hex) Bytes used
A U+0041 00 00 00 41 4
โน U+20B9 00 00 20 B9 4
๐ U+1F600 00 01 F6 00 4
For example, 'A' (65) in UTF-32 is:
00000000 00000000 00000000 01000001
Fixed Length
Every character takes exactly 4 bytes
32 bitsEasy to Locate
Every character is the same size so the 10th character always starts at byte 36
Direct accessSimple
The stored number is the code point itself with no special bit patterns
No conversion rulesUses More Space
English text needs 4 times as much space as in UTF-8
4x sizeAnalogy: Packing a tiffin ๐ฑ. UTF-8 puts each item in the smallest box it fits into โ a laddoo gets a small box, a full meal gets a big one. UTF-32 puts every item, even a single laddoo, into the same big 4-compartment tiffin. The boxes are easy to stack and count, but a lot of space is wasted!
2.4.7 UTF-8 vs UTF-32 โ๏ธ
| Feature | UTF-8 | UTF-32 |
|---|---|---|
| Type | Variable-length | Fixed-length |
| Bytes per character | 1 to 4 | Always 4 |
| Bits per character | 8, 16, 24 or 32 | Always 32 |
| 'A' is stored as | 41 (1 byte) | 00 00 00 41 (4 bytes) |
| ASCII compatible? | โ Yes โ ASCII text is already valid UTF-8 | โ No โ each ASCII character takes 4 bytes |
| Space for English text | Least (1 byte per character) | 4 times more than UTF-8 |
| Finding the nth character | Must read from the start, as sizes vary | Direct โ every character is 4 bytes |
| Common use | Web pages, emails, text files, Python source code | Internal processing inside some programs |
Worked example โ counting storage:
| Text | Characters (code points) | UTF-8 bytes | UTF-32 bytes |
|---|---|---|---|
| CSIP | 4 | 4 ร 1 = 4 | 4 ร 4 = 16 |
| Hiโน | 3 | 1 + 1 + 3 = 5 | 3 ร 4 = 12 |
| เคจเคฎเคธเฅเคคเฅ | 6 (เคจ เคฎ เคธ เฅ เคค เฅ) | 6 ร 3 = 18 | 6 ร 4 = 24 |
Notice that เคจเคฎเคธเฅเคคเฅ looks like 4 letters but is stored as 6 code points โ the half-letter sign ( เฅ ) and the matra ( เฅ ) are separate Unicode characters.
Try it yourself โ Python's encode() method turns a string into bytes, so len() of the result is the number of bytes used:
for ch in ["A", "รฉ", "โน", "เค
", "๐"]:
u8 = ch.encode("utf-8")
u32 = ch.encode("utf-32-be")
print(ch, f"U+{ord(ch):04X}", len(u8), "byte(s) in UTF-8,", len(u32), "bytes in UTF-32")
Output:
A U+0041 1 byte(s) in UTF-8, 4 bytes in UTF-32
รฉ U+00E9 2 byte(s) in UTF-8, 4 bytes in UTF-32
โน U+20B9 3 byte(s) in UTF-8, 4 bytes in UTF-32
เค
U+0905 3 byte(s) in UTF-8, 4 bytes in UTF-32
๐ U+1F600 4 byte(s) in UTF-8, 4 bytes in UTF-32
We write "utf-32-be" so that Python stores only the 4 bytes of each character. With plain "utf-32", Python adds 4 extra marker bytes at the start.
The number in the name is the starting size. UTF-8 starts at 8 bits and stretches up to 32 bits when needed. UTF-32 is set at 32 bits for every character โ no more, no less.
"Differentiate between UTF-8 and UTF-32." โ 2-mark question. Answer: UTF-8 is a variable-length Unicode encoding that uses 1 to 4 bytes per character; ASCII characters take just 1 byte, so it is space-saving and backward compatible with ASCII. UTF-32 is a fixed-length Unicode encoding that uses exactly 4 bytes (32 bits) for every character; it is simple and allows direct access to any character, but it uses more memory.
"How many bytes are needed to store the string Hiโน in UTF-8 and in UTF-32?" โ 2-mark question. Answer: In UTF-8, H and i take 1 byte each and โน (U+20B9) takes 3 bytes, so the total is 1 + 1 + 3 = 5 bytes. In UTF-32, every character takes 4 bytes, so the total is 3 ร 4 = 12 bytes.
โ ๏ธ Common Errors and Misconceptions
| Mistake | What's Wrong | Correct Understanding |
|---|---|---|
| โ Reading remainders TOP to BOTTOM in DecimalโBinary conversion | Gives the WRONG answer, reversed | โ Always read remainders BOTTOM to TOP |
| โ Forgetting to pad binary groups with zeros | Incomplete/wrong grouping for Octal/Hex conversion | โ Add leading zeros to complete groups of 3 (octal) or 4 (hex) |
| โ Thinking Octal-to-Hex can be done directly | No direct shortcut exists | โ ALWAYS convert through Binary as the middle step |
| โ ASCII and Unicode are the same thing | Unicode covers vastly more characters | โ ASCII = English only (128-256 chars); Unicode = ALL world languages (1M+ chars) |
| โ ISCII can represent English AND Indian languages equally | ISCII is designed specifically for Indian scripts | โ ISCII was created specifically to fill the gap ASCII left for Indian languages |
| โ 'a' and 'A' have the same ASCII value | They are different values | โ Lowercase = Uppercase value + 32 (e.g., 'A'=65, 'a'=97) |
| โ UTF-8 stores every character in 8 bits | UTF-8 is variable-length | โ UTF-8 uses 1 to 4 bytes โ only ASCII characters fit in 1 byte (โน takes 3, ๐ takes 4) |
| โ UTF-32 saves space because it is fixed | Fixed size means 4 bytes even for 'A' | โ UTF-32 always uses 4 bytes per character, so it needs the MOST space for English text |
| โ Unicode and UTF-8 are the same thing | Unicode is the character set of code points | โ Unicode gives each character a number (U+20B9); UTF-8 and UTF-32 are ways of storing that number as bytes |
Number Systems โ Bases:
Decimal = Base 10 (0-9)
Binary = Base 2 (0-1)
Octal = Base 8 (0-7)
Hex = Base 16 (0-9, A-F)
Conversion Methods โ One-Line Summary:
| From โ To | Method |
|---|---|
| Decimal โ Any Base | Repeated division; read remainders bottom-to-top |
| Any Base โ Decimal | Multiply digits by positional powers; add |
| Binary โ Octal | Group in 3s |
| Binary โ Hex | Group in 4s |
| Octal โ Binary | 3-bit expansion per digit |
| Hex โ Binary | 4-bit expansion per digit |
| Octal โ Hex | Always convert VIA Binary |
Character Encoding โ Quick Table:
| Code | Covers | Bit Size |
|---|---|---|
| ASCII | English only | 7-8 bits |
| ISCII | Indian languages | 8 bits |
| Unicode | ALL world languages | 16+ bits |
| UTF-8 | All Unicode characters (variable-length) | 8, 16, 24 or 32 bits (1-4 bytes) |
| UTF-32 | All Unicode characters (fixed-length) | Always 32 bits (4 bytes) |
Unicode encodings in one line each:
- Code point โ Unicode's number for a character, written U+hex (A = U+0041, โน = U+20B9)
- UTF-8 โ 1 to 4 bytes per character; ASCII = 1 byte; ASCII compatible; saves space; used on the web
- UTF-32 โ always 4 bytes per character; simple, direct access; uses the most space
- Storage โ UTF-8: add each character's bytes; UTF-32: number of characters ร 4
๐ฏ Sample Exam Questions
Q1: Very Short Answer [1 mark each]
a) What is the base of the Hexadecimal number system? โ 16
b) What does ASCII stand for? โ American Standard Code for Information Interchange
c) How many bits make up 1 byte? โ 8 bits
d) What is the ASCII value of the character 'A'? โ 65
e) Which number system uses digits 0-7 only? โ Octal
f) How many bytes does UTF-32 use to store any one character? โ 4 bytes (32 bits)
g) How many bytes does the letter 'A' take in UTF-8? โ 1 byte
Q2: Conversion [2 marks]
Q: Convert (45)โโ to Binary.
45 รท 2 = 22 remainder 1
22 รท 2 = 11 remainder 0
11 รท 2 = 5 remainder 1
5 รท 2 = 2 remainder 1
2 รท 2 = 1 remainder 0
1 รท 2 = 0 remainder 1
Answer: (45)โโ = (101101)โ
Q3: Conversion [2 marks]
Q: Convert (11010)โ to Decimal.
1 1 0 1 0
16 8 4 2 1
(1ร16)+(1ร8)+(0ร4)+(1ร2)+(0ร1) = 16+8+0+2+0 = 26
Answer: (11010)โ = (26)โโ
Q4: Conversion [3 marks]
Q: Convert (1101 1010)โ to Octal and Hexadecimal.
To Octal (group in 3s):
011 011 010
011 = 3, 011 = 3, 010 = 2
Answer: 332
To Hex (group in 4s):
1101 1010
1101 = D, 1010 = A
Answer: DA
Q5: Short Answer [2 marks]
Q: Differentiate between ASCII and Unicode.
ASCII is a 7-8 bit encoding covering only English letters, digits, and symbols (128-256 characters). Unicode is a universal 16+ bit encoding that represents characters from ALL world languages, including emojis โ with the first 128 values matching ASCII for backward compatibility.
Q6: Short Answer [2 marks]
Q: Differentiate between UTF-8 and UTF-32.
| UTF-8 | UTF-32 |
|---|---|
| Variable-length encoding | Fixed-length encoding |
| Uses 1 to 4 bytes per character | Uses exactly 4 bytes for every character |
| ASCII characters take 1 byte, so it is backward compatible with ASCII | Even ASCII characters take 4 bytes |
| Saves storage space | Uses more space but allows direct access to any character |
Q7: Application [3 marks]
Q: The word INDIAโน is to be stored. (a) How many bytes are needed in UTF-8? (b) How many in UTF-32? (c) Which encoding is better for storing mostly English text, and why?
Characters: I N D I A โน โ 6 characters
UTF-8 : I, N, D, I, A = 1 byte each = 5 bytes; โน (U+20B9) = 3 bytes
Total = 5 + 3 = 8 bytes
UTF-32: 6 characters ร 4 bytes = 24 bytes
Answer: (a) 8 bytes (b) 24 bytes (c) UTF-8, because English (ASCII) characters take only 1 byte each in UTF-8 but 4 bytes each in UTF-32.
โ๏ธ Practice Problems
-
Convert (78)โโ to Binary, Octal, and Hexadecimal.
-
Convert (110101)โ to Decimal, Octal, and Hexadecimal.
-
Convert (BC)โโ to Decimal and Binary.
-
Convert (57)โ to Decimal and Binary.
-
Explain why Octal-to-Hexadecimal conversion requires going through Binary as an intermediate step.
-
What is the ASCII value of 'Z'? What would the ASCII value of 'z' be, using the +32 shortcut?
-
Differentiate between ASCII, ISCII, and Unicode with one key feature of each.
-
Convert the decimal number 500 into Binary, Octal, and Hexadecimal, showing all working steps.
-
Explain why computers use the Binary number system internally, rather than Decimal.
-
A student converts (25)โโ to binary and gets (10011)โ instead of the correct (11001)โ. Identify the likely mistake made during the conversion process.
-
Write the Unicode code point of 'A' and explain why it is the same as its ASCII value.
-
How many bytes are needed to store the string "Class 11" in UTF-8 and in UTF-32? (Remember that the space is also a character.)
-
Give two advantages of UTF-8 over UTF-32 and one advantage of UTF-32 over UTF-8.