1.1.2How Computers Work

Hexadecimal and octal — conversions, why they're used

1,706 words8 min readdifficulty · medium1 backlinks

WHAT are these number systems?


The power-of-2 shortcut (the key skill)

Figure — Hexadecimal and octal — conversions, why they're used

Worked examples


Common mistakes (steel-manned)


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 1616 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.


WHY hex/octal matter in real computing

  • 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.

Flashcards

Why is hexadecimal preferred over decimal for representing binary?
Because 16=2416=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=238=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 1101011021101\,0110_2 to hex.
D6D6 (1101=13=D, 0110=6).
Convert 70010700_{10} to hex using repeated division.
2BC2BC (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 (202^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?
NmodbN \bmod b equals the units digit d0d_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 0x2BC0x2BC to binary instantly.
2=0010, B=1011, C=1100 → 101011110021010111100_2.

Connections

  • Binary number system — the underlying base hex/octal abbreviate.
  • Positional notation and place value — the master equation N=dibiN=\sum 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.

Concept Map

hard for humans

need shorthand

2^3

2^4

1 digit = 3 bits

1 digit = 4 bits

derived from

repeated division

converts to

sum digits

Binary base-2

Human unreadable long strings

Base = power of 2

Octal base-8

Hex base-16

Place value equation N=sum di b^i

Group bits, no arithmetic

Divide-remainder for decimal

Decimal value

Hinglish (regional understanding)

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 = 232^3) aur hexadecimal (base-16 = 242^4). Yahi inka pura raaz hai.

Kyunki 16=2416 = 2^4, ek hex digit exactly 4 bits ke barabar hota hai, aur kyunki 8=238 = 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.

Go deeper — visual, from zero

Test yourself — How Computers Work

Connections