Binary, decimal, hex — the quick answer
Every number can be written in any base: binary (base 2) uses only 0–1, octal (base 8) uses 0–7, decimal (base 10) uses 0–9, and hexadecimal (base 16) uses 0–9 plus A–F. The same value wears different clothes — 255 in decimal is 11111111 in binary and FF in hex.
The trick to remember: each hex digit is exactly 4 bits, so one byte (8 bits) is always two hex digits. That's why programmers write colors as #FF5733 and memory addresses in hex — it's binary, compressed for human eyes.
A short history: from Leibniz to the byte
Binary is far older than computers. In 1703, Gottfried Wilhelm Leibniz published the first formal treatment of base-2 arithmetic, fascinated that all numbers could be built from just 0 and 1. It stayed a mathematical curiosity until 1854, when George Boole's algebra of true/false gave binary a logic to run on.
Early computers actually flirted with octal — groups of 3 bits fit the 12-, 24- and 36-bit machines of the 1960s. But when IBM's System/360 (1964) standardized the 8-bit byte, hexadecimal won: one byte = exactly two hex digits, no awkward leftovers. Programmers have written 0x prefixes and A–F digits ever since, while decimal remains the base humans do arithmetic in.
Octal never fully died — Unix file permissions like chmod 755 are still octal, three bits per digit, three digits per permission set. Every base survives where it fits best.
How it works: the place-value formula
Each digit's value = digit × baseposition, counting positions from 0 at the right:
1×2³ + 0×2² + 1×2¹ + 0×2⁰ = 8 + 0 + 2 + 0 = 10.
F = 15, so 15×16¹ + 15×16⁰ = 240 + 15 = 255 — the maximum value of one byte.
255 ÷ 16 = 15 remainder 15 → digits 15, 15 → FF. (Read remainders right-to-left.)
Number base conversion table (0–32)
Decimal alongside binary, octal and hexadecimal:
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 17 | 10001 | 21 | 11 |
| 18 | 10010 | 22 | 12 |
| 19 | 10011 | 23 | 13 |
| 20 | 10100 | 24 | 14 |
| 21 | 10101 | 25 | 15 |
| 22 | 10110 | 26 | 16 |
| 23 | 10111 | 27 | 17 |
| 24 | 11000 | 30 | 18 |
| 25 | 11001 | 31 | 19 |
| 26 | 11010 | 32 | 1A |
| 27 | 11011 | 33 | 1B |
| 28 | 11100 | 34 | 1C |
| 29 | 11101 | 35 | 1D |
| 30 | 11110 | 36 | 1E |
| 31 | 11111 | 37 | 1F |
| 32 | 100000 | 40 | 20 |
Landmark numbers across the bases
Certain values show up everywhere in computing — here's how they look in each base:
The biggest single hex digit — binary 1111, four 1-bits.
11111111₂, 377₈, FF₁₆ — the largest number one byte can hold.
10000000000₂, 2000₈, 400₁₆ — the kilo that started the 1000-vs-1024 debate.
FFFF₁₆ — the largest unsigned integer in 16 bits, a classic old limit.
FFFFFF₁₆ — every color your screen can show, in one hex number.
"There are 10 types of people: those who understand binary and those who don't."
Visual guide: binary place values
Read binary like decimal — each column is worth the base times the column to its right. Here 1011₂ adds up to 11:
Figure: each binary column doubles in value moving left — add the columns holding a 1 to get the decimal value.
Common mistakes to avoid
Base conversions have sharp edges. Avoid these four:
- Using digit 8 or 9 in octal. Octal digits run 0–7 only — "8" and "9" don't exist in base 8. The converter above flags invalid digits instead of guessing.
- Reading hex letters as words. In FF₁₆, each F is the digit fifteen, not a letter. F×16 + F = 240 + 15 = 255 — treat A–F as the numbers 10–15.
- Dropping leading zeros when grouping. To turn binary into hex, group in fours from the right: 101₂ must become 0101₂ = 5₁₆, not 101 grouped wrongly.
- Forgetting the 0x prefix is not part of the number. 0xFF and FF are the same value — the 0x just announces "hex ahead." Don't try to convert the x.
Pro tips & mental math
Convert like a programmer with these shortcuts:
- Hex → binary: one digit at a time. Each hex digit is 4 bits: F = 1111, A = 1010, 5 = 0101. So 0xFA = 1111 1010 — no division needed.
- Binary → decimal: double and add. Scan left to right, doubling your running total and adding each bit: 1011 → 1, 2, 5, 11. Fast and error-proof.
- Anchor on powers of two. 2¹⁰ = 1,024, 2¹⁶ = 65,536, 2⁸ = 256. Most "magic numbers" in computing are one of these — or one less.
- One byte = two hex digits, always. If your hex has an odd number of digits, pad a leading zero: 0xABC is really 0x0ABC. Bytes come in pairs.
Printable cheat sheet
Want the 0–32 base table on paper? Print a clean, ink-friendly cheat sheet with one click — the page header, widgets and navigation are automatically hidden in the printout:
Fun facts
- Leibniz saw theology in binary. He believed base 2 — everything from 1 (God) and 0 (nothing) — proved creation ex nihilo, and had a medallion minted to celebrate the idea.
- Your screen colors are hex numbers. #FF5733 means red=FF (255), green=57 (87), blue=33 (51) — every web color is just three bytes written in hexadecimal.
- Programmers joke in binary. "There are only 10 kinds of people in the world: those who understand binary and those who don't" — 10₂ is 2, so the joke counts exactly two kinds.
- IPv6 addresses are pure hex. An address like 2001:0db8::1 packs 128 bits into 32 hex digits — written in decimal it would be 39 digits long and unreadable.
The complete guide
It starts with why we count in tens at all, then explains binary, octal, and hexadecimal, with hand conversions worked out step by step.
Frequently asked questions
What is hexadecimal used for?
Hexadecimal is shorthand for binary: each hex digit represents exactly 4 bits. It's used for memory addresses, color codes like #FF5733, IPv6 addresses, and anywhere long binary strings need a compact, readable form.
Why do computers use binary?
Hardware works with switches that are on or off, which maps perfectly to two digits: 0 and 1. Binary is the only number system circuits can represent directly and reliably.
How do I convert binary to decimal?
Add the place values of each 1-bit: from the right, the columns are 1, 2, 4, 8, 16 and so on. Example: 1010 = 8 + 0 + 2 + 0 = 10.
What is the difference between octal and hexadecimal?
Both are compact ways to write binary. Octal uses digits 0–7 (each digit = 3 bits) and was popular on early computers; hexadecimal uses 0–9 and A–F (each digit = 4 bits) and won because one byte is exactly two hex digits.
What does the 0x prefix mean?
0x marks a number as hexadecimal in most programming languages — 0xFF means hex FF, which is 255 in decimal. Similarly, 0b marks binary and 0o marks octal.
How many bits are in one hex digit?
Four bits. Each hex digit (0–F) covers values 0–15, which is exactly the range of 4 binary digits. That's why one byte (8 bits) is always written as two hex digits.
Related tools
More digital and math tools:
