Binary, octal, decimal, and hexadecimal are different ways to represent the same numbers. Understanding base conversion is fundamental for programming, networking, and working with low-level systems.
The bases
| Base | Name | Digits | Common use |
|---|---|---|---|
| 2 | Binary | 0, 1 | Hardware, bitwise operations |
| 8 | Octal | 0-7 | Unix file permissions |
| 10 | Decimal | 0-9 | Human math |
| 16 | Hexadecimal | 0-9, A-F | Colors, memory addresses, bytes |
How base conversion works
In decimal, each position is a power of 10:
354 = 3×10² + 5×10¹ + 4×10⁰
= 300 + 50 + 4 In binary, each position is a power of 2:
1011 = 1×2³ + 0×2² + 1×2¹ + 1×2⁰
= 8 + 0 + 2 + 1
= 11 (decimal) In hexadecimal, each position is a power of 16:
2F = 2×16¹ + F(15)×16⁰
= 32 + 15
= 47 (decimal) Hexadecimal in practice
Hex is the most commonly encountered non-decimal base:
Colors
#FF6B35 = R:255 G:107 B:53 Each pair of hex digits (00-FF) represents a value from 0-255.
Memory addresses
0x7FFF5FBFFA10 Debuggers and system tools show addresses in hex because they’re more compact than binary.
Byte values
One hex digit = 4 bits. Two hex digits = 1 byte (8 bits). This makes hex a compact representation of binary data.
Binary: 1111 1010
Hex: F A Binary in practice
Bitwise operations
Flags, permissions, and masks use binary:
Read: 100 (4)
Write: 010 (2)
Execute: 001 (1)
R+W+X: 111 (7) Network masks
255.255.255.0 = 11111111.11111111.11111111.00000000
/24 subnet = 24 ones followed by 8 zeros Powers of 2
Every programmer should recognize these:
2⁰ = 1
2¹ = 2
2⁸ = 256
2¹⁰ = 1024 (1 KiB)
2¹⁶ = 65536
2³² = 4,294,967,296 (~4.3 billion) Octal in practice
Octal is mainly used for Unix file permissions:
chmod 755 file.sh Breaking it down:
- 7 = rwx (owner: read+write+execute)
- 5 = r-x (group: read+execute)
- 5 = r-x (others: read+execute)
Each octal digit maps to 3 binary bits, making it a natural fit for 3-bit permission groups.
Quick conversion table
| Decimal | Binary | Hex | Octal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 5 | 0101 | 5 | 5 |
| 10 | 1010 | A | 12 |
| 15 | 1111 | F | 17 |
| 16 | 10000 | 10 | 20 |
| 255 | 11111111 | FF | 377 |
Prefixes in code
Different languages denote bases differently:
| Base | JavaScript | Python | C |
|---|---|---|---|
| Binary | 0b1010 | 0b1010 | 0b1010 |
| Octal | 0o12 | 0o12 | 012 |
| Hex | 0xFF | 0xFF | 0xFF |
A number base converter tool handles conversions between all common bases instantly — enter a number in any base and see its representation in all others.