Intuition The big picture
Computers think in binary (0s and 1s), but long binary strings like 11010110 are painful for humans to read, write, and copy without errors. Hexadecimal (base 16) and octal (base 8) are shorthand for binary . Their whole reason for existing: 16 = 2 4 16 = 2^4 16 = 2 4 and 8 = 2 3 8 = 2^3 8 = 2 3 , so each hex digit packs exactly 4 bits and each octal digit packs exactly 3 bits . Grouping bits into neat chunks lets us shrink an 8-bit byte from 8 characters to just 2 hex digits.
Intuition Steel-manning the "just use decimal" idea
Decimal (base 10) feels natural to us, so why not convert binary straight to decimal? Because 10 10 10 is not a power of 2. There's no clean, digit-by-digit mapping between decimal and binary — you have to do full division arithmetic. Hex and octal align perfectly with bit boundaries, so conversion is just chopping the binary string into groups. That's the killer feature.
b b b (radix-b b b ) number
In base b b b , a number is written as 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 , where each digit satisfies 0 ≤ d i < b 0 \le d_i < b 0 ≤ d i < b , and its value is
value = ∑ i d i ⋅ b i \text{value} = \sum_{i} d_i \cdot b^{\,i} value = ∑ i d i ⋅ b i
The exponent i i i is the position (place value). b b b is the base or radix .
System
Base b b b
Digits used
Binary
2
0,1
Octal
8
0–7
Decimal
10
0–9
Hex
16
0–9, A,B,C,D,E,F
Definition Hex letter digits
Since we run out of numeric symbols after 9, hex uses letters: A = 10 , B = 11 , C = 12 , D = 13 , E = 14 , F = 15 A=10,\ B=11,\ C=12,\ D=13,\ E=14,\ F=15 A = 10 , B = 11 , C = 12 , D = 13 , E = 14 , F = 15 .
Just plug into the definition. Multiply each digit by its place value b i b^i b i and add.
2F 16 \text{2F}_{16} 2F 16 → decimal
2 F 16 = 2 ⋅ 16 1 + 15 ⋅ 16 0 2F_{16} = 2 \cdot 16^1 + 15 \cdot 16^0 2 F 16 = 2 ⋅ 1 6 1 + 15 ⋅ 1 6 0
Why this step? By definition of base-16, the left digit has place value 16 1 16^1 1 6 1 and the right has 16 0 16^0 1 6 0 ; and F = 15 F = 15 F = 15 .
= 32 + 15 = 47 10 = 32 + 15 = 47_{10} = 32 + 15 = 4 7 10
157 8 157_8 15 7 8 → decimal
157 8 = 1 ⋅ 8 2 + 5 ⋅ 8 1 + 7 ⋅ 8 0 157_8 = 1\cdot 8^2 + 5\cdot 8^1 + 7\cdot 8^0 15 7 8 = 1 ⋅ 8 2 + 5 ⋅ 8 1 + 7 ⋅ 8 0
Why this step? Three octal digits, place values 8 2 , 8 1 , 8 0 8^2, 8^1, 8^0 8 2 , 8 1 , 8 0 .
= 64 + 40 + 7 = 111 10 = 64 + 40 + 7 = 111_{10} = 64 + 40 + 7 = 11 1 10
Intuition Why divide by the base repeatedly?
When you divide N N N by b b b , the remainder is exactly the last digit d 0 d_0 d 0 (because every higher term d i b i d_i b^i d i b i with i ≥ 1 i\ge1 i ≥ 1 is divisible by b b b , so only d 0 d_0 d 0 survives as the remainder). The quotient is the number "shifted right" by one digit. Repeat, reading remainders bottom-up.
47 10 47_{10} 4 7 10 → hex
47 ÷ 16 = 2 r 15 ( = F ) 2 ÷ 16 = 0 r 2 47 \div 16 = 2 \text{ r } 15\;(=F) \qquad 2 \div 16 = 0 \text{ r } 2 47 ÷ 16 = 2 r 15 ( = F ) 2 ÷ 16 = 0 r 2
Read remainders bottom→top: 2 , F ⇒ 2 F 16 2, F \Rightarrow \mathbf{2F_{16}} 2 , F ⇒ 2 F 16 .
Why bottom→top? The first remainder is the lowest place value (16 0 16^0 1 6 0 ), so it must go on the right.
11010110 2 11010110_2 1101011 0 2 → hex
Group into 4s from the right: 1101 ⏟ D 0110 ⏟ 6 \;\underbrace{1101}_{D}\ \underbrace{0110}_{6} D 1101 6 0110
⇒ D 6 16 \Rightarrow \mathbf{D6_{16}} ⇒ D 6 16
Why from the right? Place value starts at 2 0 2^0 2 0 on the right; grouping must respect that boundary or the powers won't line up as clean 16 i 16^i 1 6 i blocks.
Check: 1101 2 = 13 = D 1101_2 = 13 = D 110 1 2 = 13 = D , 0110 2 = 6 \;0110_2 = 6 011 0 2 = 6 . ✓
11010110 2 11010110_2 1101011 0 2 → octal
Group into 3s from the right: 011 ⏟ 3 010 ⏟ 2 110 ⏟ 6 \;\underbrace{011}_{3}\ \underbrace{010}_{2}\ \underbrace{110}_{6} 3 011 2 010 6 110
(pad the leftmost group 11 to 011)
⇒ 326 8 \Rightarrow \mathbf{326_8} ⇒ 32 6 8
Why pad? 8 8 8 bits isn't a multiple of 3 3 3 ; padding the left with zeros doesn't change the value.
Worked example Hex → octal (go via binary)
2F 16 \text{2F}_{16} 2F 16 : expand each hex digit to 4 bits → 0010 1111 0010\,1111 0010 1111 . Regroup into 3s from the right: 00 ⏟ 101111 → 0 010 1111 → 101 ⏟ 5 111 ⏟ 7 \underbrace{00}_{}101111 \to 0\,010\,1111 \to \underbrace{101}_{5}\underbrace{111}_{7} 00 101111 → 0 010 1111 → 5 101 7 111 with leading 0 0 0 → 101111 2 101111_2 10111 1 2 = 57 8 57_8 5 7 8 .
Why via binary? Hex and octal don't align with each other (their group sizes 4 and 3 differ), but both align with binary — so binary is the universal middle-man.
Definition How bases are marked in real hardware/code
Subscript: 2F 16 \text{2F}_{16} 2F 16 , 101 2 101_2 10 1 2 , 17 8 17_8 1 7 8 .
Hex prefix: 0x2F (C, Python) or $2F (assembly) or 2Fh.
Octal prefix: 0o17 (Python) or leading 0 like 017 (old C).
Binary prefix: 0b101.
Common mistake Grouping bits from the LEFT
Why it feels right: We read English left-to-right, so we start grouping on the left.
Why it's wrong: Place values grow from the right (2 0 , 2 1 , … 2^0, 2^1,\dots 2 0 , 2 1 , … ). Grouping from the left mis-aligns the powers.
Fix: Always group from the right ; pad the leftmost group with leading zeros.
Common mistake Forgetting that
A A A –F F F are digits, not variables
Why it feels right: Letters usually mean unknowns in maths.
Fix: In hex, A A A –F F F are fixed values 10 10 10 –15 15 15 . 0xFF = 15 ⋅ 16 + 15 = 255 = 15\cdot16 + 15 = 255 = 15 ⋅ 16 + 15 = 255 .
Common mistake Mixing hex directly with octal by "digit swapping"
Why it feels right: Both are just "grouped binary," so it seems you could swap groups.
Fix: 4 4 4 -bit and 3 3 3 -bit groups don't line up. Always route through binary .
10 10 10 means "ten" in every base
Fix: 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 . In any base b b b , "10 10 10 " means b b b itself.
Recall Feynman: explain to a 12-year-old
Imagine binary is a super long word made only of the letters I and O, and it's easy to miscopy. Hex is like a secret code where every 4 letters get a single nickname (0–9, then A–F). Octal does the same but with 3 letters per nickname. So a giant binary word becomes a short, tidy code. To decode, you just re-spell each nickname back into its little bits — no maths needed. Ten (decimal) can't do this trick because 10 10 10 isn't made of pure "doublings" like 8 and 16 are.
Mnemonic Remember the group sizes
"Hex has 4 legs, Octal has 3 legs." (Hex = 2 4 → 4 = 2^4 \to 4 = 2 4 → 4 bits; Octal = 2 3 → 3 =2^3 \to 3 = 2 3 → 3 bits.) Also: F ifteen is the biggest hex digit (F = 15 F=15 F = 15 ).
Why does one hex digit map to exactly 4 bits? Because
16 = 2 4 16 = 2^4 16 = 2 4 , so hex digits
0 0 0 –
15 15 15 correspond one-to-one with the 16 patterns of 4 bits.
Why does one octal digit map to exactly 3 bits? Because
8 = 2 3 8 = 2^3 8 = 2 3 ; the 8 octal digits cover all 8 patterns of 3 bits.
What is the value of hex digit F F F ? Convert 101 2 101_2 10 1 2 's value in the words "one zero one" — what is 10 10 10 in base b b b ? In any base
b b b , "
10 10 10 " equals
b b b itself (
10 2 = 2 10_2=2 1 0 2 = 2 ,
10 16 = 16 10_{16}=16 1 0 16 = 16 ).
When grouping binary into hex, from which side do you group and why? From the
right , because place values (
2 0 , 2 1 , … 2^0,2^1,\dots 2 0 , 2 1 , … ) start on the right; pad the left with zeros.
Convert 2F 16 \text{2F}_{16} 2F 16 to decimal. 2 ⋅ 16 + 15 = 47 2\cdot16 + 15 = 47 2 ⋅ 16 + 15 = 47 .
Convert 11010110 2 11010110_2 1101011 0 2 to hex. 1101 0110 = D6 16 1101\,0110 = \text{D6}_{16} 1101 0110 = D6 16 .
Convert 11010110 2 11010110_2 1101011 0 2 to octal. 011 010 110 = 326 8 011\,010\,110 = 326_8 011 010 110 = 32 6 8 .
Why convert hex↔octal via binary? 4-bit and 3-bit groups don't align with each other, but both align with binary, the common middle-man.
In repeated division to convert decimal→base b b b , why do we read remainders bottom-to-top? The first remainder is the lowest place value (
b 0 b^0 b 0 ), so it belongs on the right (last read).
What does 0xFF equal in decimal? 255 255 255 (
15 ⋅ 16 + 15 15\cdot16+15 15 ⋅ 16 + 15 ).
16 equals 2^4 packs 4 bits
8 equals 2^3 packs 3 bits
Intuition Hinglish mein samjho
Dekho, computer sirf 0 aur 1 samajhta hai — yaani binary. Lekin humare liye 11010110 jaisa lamba binary padhna aur likhna bahut error-prone hai. Isiliye hum hexadecimal (base 16) aur octal (base 8) use karte hain — ye basically binary ka short-form hain. Trick simple hai: 16 = 2 4 16 = 2^4 16 = 2 4 hota hai, isliye ek hex digit exactly 4 bits ko represent karta hai; aur 8 = 2 3 8 = 2^3 8 = 2 3 hota hai, isliye ek octal digit exactly 3 bits ko. Bas binary ko group kar do aur nickname likh do.
Conversion ka rule yaad rakho: binary ko right side se group karo (4 ke, ya 3 ke), kyunki place value right se hi start hota hai (2 0 , 2 1 , … 2^0, 2^1,\dots 2 0 , 2 1 , … ). Agar bits pure nahi bante toh left mein zero pad kar do — value change nahi hoti. Jaise 11010110 → 1101 ∣ 0110 = D 6 16 11010110 \to 1101|0110 = D6_{16} 11010110 → 1101∣0110 = D 6 16 , aur 011 ∣ 010 ∣ 110 = 326 8 011|010|110 = 326_8 011∣010∣110 = 32 6 8 . Decimal se convert karna ho toh base se baar-baar divide karo aur remainders neeche se upar padho.
Ek important point: hex mein A A A se F F F tak letters actually digits hain — A = 10 A=10 A = 10 , ..., F = 15 F=15 F = 15 . Ye variable nahi hain! Aur "10 10 10 " har base mein ten nahi hota — kisi bhi base b b b mein "10 10 10 " ka matlab hota hai b b b khud (10 2 = 2 10_2=2 1 0 2 = 2 , 10 16 = 16 10_{16}=16 1 0 16 = 16 ).
Hex ko directly octal mein swap mat karna — 4-bit aur 3-bit groups match nahi karte. Hamesha binary ke through jao, kyunki binary dono ka common middle-man hai. Yehi cheez exams aur real coding (memory addresses, bit masks) dono mein kaam aati hai.