Intuition The big idea (WHY this exists)
Computers think in binary (base-2 ), but binary is painful for humans: the number 11111111 11111111 11111111 is just 255, yet it's a wall of digits. We want a shorthand that is both human-readable and trivially convertible to binary. The trick: pick a base that is a power of 2 .
8 = 2 3 8 = 2^3 8 = 2 3 → octal (base-8): one octal digit = exactly 3 bits .
16 = 2 4 16 = 2^4 16 = 2 4 → hexadecimal (base-16): one hex digit = exactly 4 bits .
Because the base is a power of 2, conversion to/from binary is just grouping bits — no division, no arithmetic. That's the whole reason these bases are used.
Definition Positional number systems
In a base-b b b system, a string of digits d n d n − 1 … d 1 d 0 d_{n}d_{n-1}\dots d_1 d_0 d n d n − 1 … d 1 d 0 means
value = ∑ i = 0 n d i ⋅ b i \text{value} = \sum_{i=0}^{n} d_i \cdot b^{\,i} value = ∑ i = 0 n d i ⋅ b i
where each digit satisfies 0 ≤ d i < b 0 \le d_i < b 0 ≤ d i < b .
Binary (b = 2 b=2 b = 2 ): digits { 0 , 1 } \{0,1\} { 0 , 1 } .
Octal (b = 8 b=8 b = 8 ): digits { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 } \{0,1,2,3,4,5,6,7\} { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 } .
Hexadecimal (b = 16 b=16 b = 16 ): digits { 0 , … , 9 , A , B , C , D , E , F } \{0,\dots,9,A,B,C,D,E,F\} { 0 , … , 9 , A , B , C , D , E , F } where ==A=10, B=11, C=12, D=13, E=14, F=15==.
Intuition WHY one hex digit = 4 bits
A 4-bit binary number ranges from 0000 0000 0000 to 1111 1111 1111 , i.e. 0 0 0 to 15 15 15 — that's exactly the 16 values one hex digit can hold. So a group of 4 bits maps one-to-one onto one hex digit, with no carrying between groups . Same logic: 3 bits range 0 0 0 –7 7 7 = one octal digit.
11010110 2 → 11010110_2 \to 1101011 0 2 → hex
Step A — group into 4s from the right: 1101 0110.
Why from the right? Because place value grows leftward; the rightmost bit is 2 0 2^0 2 0 , so the lowest group must start there to keep powers aligned.
Step B — convert each group: 1101 2 = 8 + 4 + 1 = 13 = D 1101_2 = 8+4+1 = 13 = D 110 1 2 = 8 + 4 + 1 = 13 = D ; 0110 2 = 4 + 2 = 6 0110_2 = 4+2 = 6 011 0 2 = 4 + 2 = 6 .
Answer: D 6 16 \mathbf{D6_{16}} D 6 16 .
Check via decimal: D 6 = 13 ⋅ 16 + 6 = 208 + 6 = 214 D6 = 13\cdot16 + 6 = 208+6 = 214 D 6 = 13 ⋅ 16 + 6 = 208 + 6 = 214 . And 11010110 2 = 128 + 64 + 16 + 4 + 2 = 214 11010110_2 = 128+64+16+4+2 = 214 1101011 0 2 = 128 + 64 + 16 + 4 + 2 = 214 . ✓
Worked example 2) Same binary
11010110 2 → 11010110_2 \to 1101011 0 2 → octal
Step A — group into 3s from the right: 11 010 110 → pad left → 011 010 110.
Why pad? The leftmost group needs 3 bits; missing high bits are zeros.
Step B: 011 = 3 011=3 011 = 3 , 010 = 2 010=2 010 = 2 , 110 = 6 110=6 110 = 6 .
Answer: 326 8 \mathbf{326_8} 32 6 8 .
Check: 326 8 = 3 ⋅ 64 + 2 ⋅ 8 + 6 = 192 + 16 + 6 = 214 326_8 = 3\cdot64 + 2\cdot8 + 6 = 192+16+6 = 214 32 6 8 = 3 ⋅ 64 + 2 ⋅ 8 + 6 = 192 + 16 + 6 = 214 . ✓ (Same number, three notations.)
Worked example 3) Decimal
→ \to → hex by repeated division: 700 10 700_{10} 70 0 10
Divide by 16, collect remainders (these are the digits, least-significant first ):
700 ÷ 16 = 43 r 12 ( C ) 700 \div 16 = 43 \text{ r } \mathbf{12}\;(C) 700 ÷ 16 = 43 r 12 ( C )
43 ÷ 16 = 2 r 11 ( B ) 43 \div 16 = 2 \text{ r } \mathbf{11}\;(B) 43 ÷ 16 = 2 r 11 ( B )
2 ÷ 16 = 0 r 2 2 \div 16 = 0 \text{ r } \mathbf{2} 2 ÷ 16 = 0 r 2
Read remainders bottom-to-top : 2 B C 16 \mathbf{2BC_{16}} 2B C 16 .
Why bottom-to-top? The first remainder is d 0 d_0 d 0 (the units place); the last is the highest place.
Verify: 2 ⋅ 256 + 11 ⋅ 16 + 12 = 512 + 176 + 12 = 700 2\cdot256 + 11\cdot16 + 12 = 512+176+12 = 700 2 ⋅ 256 + 11 ⋅ 16 + 12 = 512 + 176 + 12 = 700 . ✓
→ \to → binary instantly: 0x 2 B C \text{0x}\,2BC 0x 2 B C
2 = 0010 2 = 0010 2 = 0010 , B = 1011 B = 1011 B = 1011 , C = 1100 C = 1100 C = 1100 → concatenate → 0010 1011 1100 2 0010\,1011\,1100_2 0010 1011 110 0 2 . Drop leading zero: 1010111100 2 1010111100_2 101011110 0 2 .
Why no math needed? Each hex digit independently expands to its 4-bit block.
Common mistake Grouping bits from the
left
Why it feels right: We read left-to-right, so we start grouping from the left.
Why it's wrong: Place value is anchored at the rightmost bit (2 0 2^0 2 0 ). Grouping from the left misaligns the powers and corrupts every digit.
Fix: Always group from the right; pad missing high bits with 0 0 0 .
Common mistake Reading division remainders top-to-bottom
Why it feels right: We naturally read the list of remainders in the order we wrote them.
Why it's wrong: The first remainder is the units digit, the last is the most significant. Top-to-bottom reverses the number.
Fix: Read remainders bottom-to-top (last computed = leftmost digit).
Common mistake Treating hex letters as their alphabet position
Why it feels right: "A is the 1st letter, so A = 1."
Why it's wrong: In hex, letters continue counting after 9: A = 10 A=10 A = 10 , not 1.
Fix: Memorise A A A –F = 10 F = 10 F = 10 –15 15 15 .
Common mistake Forgetting the base label
Writing 10 is ambiguous: 10 2 = 2 10_2=2 1 0 2 = 2 , 10 8 = 8 10_8=8 1 0 8 = 8 , 10 16 = 16 10_{16}=16 1 0 16 = 16 . Fix: use prefixes — 0b1010 (binary), 0o12 (octal), 0x0A (hex).
Recall Feynman: explain to a 12-year-old
Imagine binary is a long zip-code of just 0s and 1s — super accurate but tiring to read. Hexadecimal is like packing every 4 of those 0/1 lights into one symbol (0–9 then A–F). Because 16 16 16 is exactly "four lights' worth" of possibilities, you can swap between the long zip-code and the short symbols just by sliding your finger 4 lights at a time — no maths, just chopping. Octal does the same but chops 3 lights at a time. Computers use these because they're the same as binary underneath, but way easier for human eyes.
Mnemonic Remember the grouping sizes
"Oct‑3, Hex‑4." Octa l groups 3 bits; hex groups 4 bits. (Octal = 8 = 2 3 2^3 2 3 → 3; Hex = 16 = 2 4 2^4 2 4 → 4.)
Memory addresses & colors: 0xFF0000 (red), addresses like 0x7FFF — compact, byte-aligned (1 byte = 2 hex digits).
Bit masks & flags: 0x0F clearly means "low 4 bits set."
File permissions (Unix): chmod 755 uses octal because permissions come in groups of 3 bits (rwx).
Debugging: memory dumps are shown in hex so each byte is a tidy 2-digit pair.
Why is hexadecimal preferred over decimal for representing binary? Because
16 = 2 4 16=2^4 16 = 2 4 , each hex digit maps to exactly 4 bits with no arithmetic — conversion is pure grouping.
How many bits does one octal digit represent, and why? 3 bits, because
8 = 2 3 8=2^3 8 = 2 3 so octal digits range 0–7 = exactly the values of 3 bits.
What is the value of hex digits A through F? A=10, B=11, C=12, D=13, E=14, F=15.
Convert 1101 0110 2 1101\,0110_2 1101 011 0 2 to hex. D 6 D6 D 6 (1101=13=D, 0110=6).
Convert 700 10 700_{10} 70 0 10 to hex using repeated division. 2 B C 2BC 2 B C (remainders 12=C, 11=B, 2 — read bottom-to-top).
When grouping binary into hex, from which side do you group, and why? From the right, because place value is anchored at the rightmost bit (
2 0 2^0 2 0 ).
When reading remainders from decimal→base-b division, which order? Bottom-to-top (last remainder is the most significant digit).
Why does repeated division by the base extract digits? N m o d b N \bmod b N mod b equals the units digit
d 0 d_0 d 0 ; dividing removes it so the next remainder is the next digit.
What do prefixes 0b, 0o, 0x mean? Binary, octal, hexadecimal literals respectively.
Convert 0 x 2 B C 0x2BC 0 x 2 B C to binary instantly. 2=0010, B=1011, C=1100 →
1010111100 2 1010111100_2 101011110 0 2 .
Binary number system — the underlying base hex/octal abbreviate.
Positional notation and place value — the master equation N = ∑ d i b i N=\sum d_i b^i N = ∑ d i b i .
Bytes and memory addressing — why 2 hex digits = 1 byte.
Bitwise operations and masks — hex makes masks readable.
Unix file permissions (chmod) — octal in practice.
ASCII and character encoding — code points shown in hex.
Human unreadable long strings
Place value equation N=sum di b^i
Group bits, no arithmetic
Divide-remainder for decimal
Intuition Hinglish mein samjho
Dekho, computer ke andar sab kuch binary (sirf 0 aur 1) mein hota hai, lekin binary padhna insaano ke liye boring aur error-prone hai — 11111111 likho toh bas 255 hota hai par aankhein thak jaati hain. Isliye hum ek aisi base choose karte hain jo 2 ka power ho: octal (base-8 = 2 3 2^3 2 3 ) aur hexadecimal (base-16 = 2 4 2^4 2 4 ). Yahi inka pura raaz hai.
Kyunki 16 = 2 4 16 = 2^4 16 = 2 4 , ek hex digit exactly 4 bits ke barabar hota hai, aur kyunki 8 = 2 3 8 = 2^3 8 = 2 3 , ek octal digit 3 bits ka. Iska matlab binary se hex/octal banane mein koi maths nahi karni padti — bas right side se 4-4 (hex) ya 3-3 (octal) bits ke group banao aur lookup table se replace kar do. Yaad rakho: hex mein 9 ke baad letters aate hain, A=10, B=11, ... F=15.
Decimal se hex ya octal jana ho toh repeated division karo: number ko base se divide karte raho, remainders collect karo, aur unhe neeche se upar padho — kyunki pehla remainder units digit hota hai. Hamesha base ka prefix likho (0b, 0o, 0x) warna 10 confusing ho jata hai.
Real life mein hex har jagah hai: memory address (0x7FFF), color codes (0xFF0000 = red), aur octal Unix permissions mein (chmod 755), kyunki rwx permissions 3-3 bits ke groups mein aate hain. Toh hex/octal kewKfshortcut hai jo binary jaisa accurate hai par human-readable bhi.