Introduction: The Conversion Map
Converting between number systems is a fundamental skill for any programmer or computer scientist. This guide covers every conversion path you'll ever need, with multiple methods for each so you can choose what works best for you.
DECIMAL
/ | \
/ | \
BINARY--+--HEXADECIMAL
\ | /
\ | /
OCTAL
Direct paths exist between all pairs!
Binary ↔ Hex and Binary ↔ Octal are trivial.
Decimal conversions require calculation.
The Key Insight
You don't need to memorize all conversion paths. Master decimal ↔ binary, and use binary as an intermediate step for others. Hex ↔ binary is trivial (4 bits = 1 hex digit), as is octal ↔ binary (3 bits = 1 octal digit).
Decimal to Binary
This is the most important conversion to master. There are three main methods, each with its advantages.
Method 1: Division by 2 (Repeated Division)
Divide by 2 repeatedly, keeping track of remainders. Read the remainders bottom to top.
Example: Convert 156 to Binary
156 ÷ 2 = 78 remainder 0 ↑
78 ÷ 2 = 39 remainder 0 |
39 ÷ 2 = 19 remainder 1 | Read
19 ÷ 2 = 9 remainder 1 | upward
9 ÷ 2 = 4 remainder 1 |
4 ÷ 2 = 2 remainder 0 |
2 ÷ 2 = 1 remainder 0 |
1 ÷ 2 = 0 remainder 1 ↓
156₁₀ = 10011100₂
Verify: 128 + 16 + 8 + 4 = 156 ✓
Example: Convert 255 to Binary
255 ÷ 2 = 127 r 1 ↑
127 ÷ 2 = 63 r 1 |
63 ÷ 2 = 31 r 1 |
31 ÷ 2 = 15 r 1 |
15 ÷ 2 = 7 r 1 |
7 ÷ 2 = 3 r 1 |
3 ÷ 2 = 1 r 1 |
1 ÷ 2 = 0 r 1 ↓
255₁₀ = 11111111₂ (all 1s = 2⁸ - 1)
Method 2: Subtraction (Power of 2 Method)
Find the largest power of 2 that fits, subtract it, and repeat. Place a 1 for each power used, 0 for each skipped.
Example: Convert 201 to Binary
Powers of 2: 256 128 64 32 16 8 4 2 1
201 - 128 = 73 → 1 (use 128)
73 - 64 = 9 → 1 (use 64)
9 - 32 = - → 0 (skip 32, too big)
9 - 16 = - → 0 (skip 16, too big)
9 - 8 = 1 → 1 (use 8)
1 - 4 = - → 0 (skip 4)
1 - 2 = - → 0 (skip 2)
1 - 1 = 0 → 1 (use 1)
201₁₀ = 11001001₂
Position: 128 64 32 16 8 4 2 1
Binary: 1 1 0 0 1 0 0 1
Method 3: Mental Math Tricks
For quick conversions, memorize these patterns:
| Pattern | Decimal | Binary |
|---|---|---|
| Powers of 2 | 1, 2, 4, 8, 16, 32, 64, 128, 256 | 1, 10, 100, 1000, 10000, ... |
| 2ⁿ - 1 | 1, 3, 7, 15, 31, 63, 127, 255 | 1, 11, 111, 1111, 11111, ... |
| Power + small | 17 = 16 + 1 | 10001 |
| Power - 1 | 127 = 128 - 1 | 1111111 |
Quick Recognition
If a number is close to a power of 2, use that as a reference. For 250: that's 256 - 6 = 100000000 - 110 = 11111010. Or 250 = 128 + 64 + 32 + 16 + 8 + 2 = 11111010.
Binary to Decimal
Method 1: Positional Notation (Standard Method)
Multiply each bit by its position value and sum:
Example: Convert 10110101 to Decimal
Position: 7 6 5 4 3 2 1 0
Power: 128 64 32 16 8 4 2 1
Binary: 1 0 1 1 0 1 0 1
Calculation:
1 × 128 = 128
0 × 64 = 0
1 × 32 = 32
1 × 16 = 16
0 × 8 = 0
1 × 4 = 4
0 × 2 = 0
1 × 1 = 1
-----
181
10110101₂ = 181₁₀
Method 2: Doubling Method (Horner's Method)
Start from the left. Double your running total and add the next bit. Repeat until done.
Example: Convert 11010110 to Decimal
Binary: 1 1 0 1 0 1 1 0
Start with 0, process left to right:
0 × 2 + 1 = 1
1 × 2 + 1 = 3
3 × 2 + 0 = 6
6 × 2 + 1 = 13
13 × 2 + 0 = 26
26 × 2 + 1 = 53
53 × 2 + 1 = 107
107 × 2 + 0 = 214
11010110₂ = 214₁₀
This method is fast for mental calculation!
Binary ↔ Hexadecimal
This conversion is trivial because 16 = 2⁴. Each hex digit corresponds to exactly 4 binary bits.
Binary to Hex
Step-by-Step Process
1. Group binary digits into sets of 4, starting from RIGHT
2. Pad with leading zeros if needed
3. Convert each group to its hex digit
Example: 1101011110 to Hex
Step 1: Group from right
11 0101 1110
Step 2: Pad to 4 bits
0011 0101 1110
Step 3: Convert
0011 = 3
0101 = 5
1110 = E
1101011110₂ = 35E₁₆
Hex to Binary
Example: Convert A7C to Binary
Simply expand each hex digit to 4 bits:
A = 1010
7 = 0111
C = 1100
A7C₁₆ = 101001111100₂
No calculation needed—just table lookup!
Memorize This Table
| Hex | Binary | Hex | Binary |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | A | 1010 |
| 3 | 0011 | B | 1011 |
| 4 | 0100 | C | 1100 |
| 5 | 0101 | D | 1101 |
| 6 | 0110 | E | 1110 |
| 7 | 0111 | F | 1111 |
Binary ↔ Octal
Similar to hex, but 8 = 2³, so each octal digit = 3 binary bits.
Binary to Octal
Example: Convert 110101011 to Octal
Step 1: Group into 3s from right
110 101 011
Step 2: Convert each group
110 = 6
101 = 5
011 = 3
110101011₂ = 653₈
Octal to Binary
Example: Convert 752 to Binary
Expand each octal digit to 3 bits:
7 = 111
5 = 101
2 = 010
752₈ = 111101010₂
Decimal ↔ Hexadecimal
Decimal to Hex (Division Method)
Divide by 16 repeatedly, keeping remainders:
Example: Convert 1000 to Hex
1000 ÷ 16 = 62 remainder 8 → 8
62 ÷ 16 = 3 remainder 14 → E
3 ÷ 16 = 0 remainder 3 → 3
Read bottom to top: 3E8₁₆
1000₁₀ = 3E8₁₆ (0x3E8)
Hex to Decimal
Example: Convert 2AF to Decimal
Position values: 16² = 256, 16¹ = 16, 16⁰ = 1
2AF₁₆:
2 × 256 = 512
A × 16 = 10 × 16 = 160
F × 1 = 15 × 1 = 15
-----
687
2AF₁₆ = 687₁₀
Alternative: Via Binary
Decimal → Binary → Hex
Convert 200 to Hex via Binary:
200₁₀ → 11001000₂ (using division by 2)
Group into 4s: 1100 1000
Convert: C 8
200₁₀ = C8₁₆
Decimal ↔ Octal
Decimal to Octal
Example: Convert 500 to Octal
500 ÷ 8 = 62 remainder 4
62 ÷ 8 = 7 remainder 6
7 ÷ 8 = 0 remainder 7
Read bottom to top: 764₈
500₁₀ = 764₈
Octal to Decimal
Example: Convert 755 to Decimal
Position values: 8² = 64, 8¹ = 8, 8⁰ = 1
755₈:
7 × 64 = 448
5 × 8 = 40
5 × 1 = 5
-----
493
755₈ = 493₁₀ (chmod 755 in decimal)
Hexadecimal ↔ Octal
No direct conversion exists. Use binary as intermediate:
Example: Convert 1F (Hex) to Octal
Step 1: Hex to Binary
1F₁₆ = 0001 1111₂
Step 2: Regroup for Octal (3 bits)
00 011 111 = 0 3 7
1F₁₆ = 37₈
Verify: 1F = 31₁₀, 37₈ = 3×8 + 7 = 31₁₀ ✓
Example: Convert 755 (Octal) to Hex
Step 1: Octal to Binary
755₈ = 111 101 101₂
Step 2: Regroup for Hex (4 bits)
0001 1110 1101 = 1 E D
755₈ = 1ED₁₆
Verify: 755₈ = 493₁₀, 1ED₁₆ = 256+224+13 = 493₁₀ ✓
Converting Fractions
Decimal Fraction to Binary
Multiply by 2 repeatedly, extracting the integer part:
Example: Convert 0.625 to Binary
0.625 × 2 = 1.25 → 1
0.25 × 2 = 0.50 → 0
0.50 × 2 = 1.00 → 1
0.00 × 2 = 0.00 → done!
Read top to bottom: 0.625₁₀ = 0.101₂
Verify: 0.101₂ = 1/2 + 0/4 + 1/8
= 0.5 + 0 + 0.125 = 0.625 ✓
Example: Convert 0.1 to Binary (Repeating!)
0.1 × 2 = 0.2 → 0
0.2 × 2 = 0.4 → 0
0.4 × 2 = 0.8 → 0
0.8 × 2 = 1.6 → 1
0.6 × 2 = 1.2 → 1
0.2 × 2 = 0.4 → 0 ← pattern repeats!
0.1₁₀ = 0.0001100110011...₂ (repeating)
This is why 0.1 can't be stored exactly!
Binary Fraction to Decimal
Example: Convert 0.1101 to Decimal
Position values: 2⁻¹=0.5, 2⁻²=0.25, 2⁻³=0.125, 2⁻⁴=0.0625
0.1101₂:
1 × 0.5 = 0.5
1 × 0.25 = 0.25
0 × 0.125 = 0
1 × 0.0625 = 0.0625
------
0.8125
0.1101₂ = 0.8125₁₀
Power User Shortcuts
Instant Recognitions
| Pattern | Binary | Hex | Decimal |
|---|---|---|---|
| All 1s (8-bit) | 11111111 | FF | 255 |
| All 1s (16-bit) | 16 ones | FFFF | 65535 |
| High bit set | 10000000 | 80 | 128 |
| MSB + LSB | 10000001 | 81 | 129 |
| Alternating | 10101010 | AA | 170 |
| Alternating | 01010101 | 55 | 85 |
Quick Calculations
Adding 1 to Binary
Flip all trailing 1s to 0, then flip the first 0 to 1. Example: 10111 + 1 = 11000
Multiplying by 2
Shift left, add a 0 at right. 1011 × 2 = 10110
Dividing by 2
Shift right, remove rightmost bit. 1011 ÷ 2 = 101 (remainder 1)
Checking if Power of 2
Has exactly one 1 bit. 1000 = power of 2. 1010 = not power of 2.
Byte Values to Know
| Decimal | Hex | Binary | Significance |
|---|---|---|---|
| 0 | 00 | 00000000 | Null, zero |
| 1 | 01 | 00000001 | Minimum positive |
| 127 | 7F | 01111111 | Max signed byte |
| 128 | 80 | 10000000 | Min signed byte (-128) |
| 255 | FF | 11111111 | Max unsigned byte |
| 10 | 0A | 00001010 | Newline (LF) |
| 32 | 20 | 00100000 | Space |
| 48 | 30 | 00110000 | '0' (zero digit) |
| 65 | 41 | 01000001 | 'A' |
| 97 | 61 | 01100001 | 'a' |
Quick Reference Tables
Powers of 2
| Power | Value | Binary | Common Name |
|---|---|---|---|
| 2⁰ | 1 | 1 | |
| 2¹ | 2 | 10 | |
| 2² | 4 | 100 | |
| 2³ | 8 | 1000 | |
| 2⁴ | 16 | 10000 | |
| 2⁵ | 32 | 100000 | |
| 2⁶ | 64 | 1000000 | |
| 2⁷ | 128 | 10000000 | |
| 2⁸ | 256 | 100000000 | |
| 2¹⁰ | 1,024 | 10000000000 | 1 KB |
| 2¹⁶ | 65,536 | 64 KB | |
| 2²⁰ | 1,048,576 | 1 MB | |
| 2³⁰ | ~1 billion | 1 GB | |
| 2³² | ~4.3 billion | 4 GB |
0-15 in All Bases
| Dec | Bin | Oct | Hex | Dec | Bin | Oct | Hex |
|---|---|---|---|---|---|---|---|
| 0 | 0000 | 0 | 0 | 8 | 1000 | 10 | 8 |
| 1 | 0001 | 1 | 1 | 9 | 1001 | 11 | 9 |
| 2 | 0010 | 2 | 2 | 10 | 1010 | 12 | A |
| 3 | 0011 | 3 | 3 | 11 | 1011 | 13 | B |
| 4 | 0100 | 4 | 4 | 12 | 1100 | 14 | C |
| 5 | 0101 | 5 | 5 | 13 | 1101 | 15 | D |
| 6 | 0110 | 6 | 6 | 14 | 1110 | 16 | E |
| 7 | 0111 | 7 | 7 | 15 | 1111 | 17 | F |
Practice Problems
Decimal to Binary
Problem 1: Convert 173 to binary
Show Solution
Using subtraction method:
173 - 128 = 45 → 1
45 - 64 = - → 0
45 - 32 = 13 → 1
13 - 16 = - → 0
13 - 8 = 5 → 1
5 - 4 = 1 → 1
1 - 2 = - → 0
1 - 1 = 0 → 1
173₁₀ = 10101101₂
Problem 2: Convert 1000 to binary
Show Solution
1000 = 512 + 256 + 128 + 64 + 32 + 8
= 2⁹ + 2⁸ + 2⁷ + 2⁶ + 2⁵ + 2³
1000₁₀ = 1111101000₂
Binary to Decimal
Problem 3: Convert 11011011 to decimal
Show Solution
Using doubling method:
1→1, ×2+1=3, ×2+0=6, ×2+1=13,
×2+1=27, ×2+0=54, ×2+1=109, ×2+1=219
11011011₂ = 219₁₀
Mixed Conversions
Problem 4: Convert 0xDEAD to binary and decimal
Show Solution
Binary: D=1101, E=1110, A=1010, D=1101
0xDEAD = 1101111010101101₂
Decimal:
D×16³ = 13×4096 = 53248
E×16² = 14×256 = 3584
A×16¹ = 10×16 = 160
D×16⁰ = 13×1 = 13
------
57005
Problem 5: Convert 644 (octal) to hex
Show Solution
Octal to Binary:
6=110, 4=100, 4=100
644₈ = 110100100₂
Binary to Hex (group by 4):
0001 1010 0100 = 1A4₁₆
644₈ = 1A4₁₆
Summary
You now have a complete toolkit for converting between any number systems:
- Decimal ↔ Binary: Division/subtraction for to-binary, positional/doubling for to-decimal
- Binary ↔ Hex: Group/ungroup by 4 bits
- Binary ↔ Octal: Group/ungroup by 3 bits
- Decimal ↔ Hex/Octal: Division method or go through binary
- Fractions: Multiply by 2 for to-binary, sum position values for to-decimal
With practice, these conversions become second nature. The key is understanding that all methods are based on place value—whether the base is 2, 8, 10, or 16.