A practical guide to number systems — how binary, octal, and hexadecimal work, why developers need them, and how to convert between bases quickly.
Most people learn decimal (base 10) and stop there. But as a developer, you'll regularly encounter binary, octal, and hexadecimal — in file permissions, color codes, memory addresses, bit flags, and character encodings. This guide makes these systems intuitive.
Computers only understand binary (0s and 1s). All other number systems are just convenient ways for humans to read binary data:
Binary uses only 0 and 1. Each position is a power of 2:
Position: 8 4 2 1
Binary: 1 0 1 1 = 8 + 0 + 2 + 1 = 11 (decimal)
Divide repeatedly by 2, record remainders from bottom to top:
42 ÷ 2 = 21 remainder 0
21 ÷ 2 = 10 remainder 1
10 ÷ 2 = 5 remainder 0
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
Read remainders bottom to top: 101010
42 in decimal = 101010 in binary
// Decimal to binary
(42).toString(2); // '101010'
// Binary to decimal
parseInt('101010', 2); // 42
// Binary literals
const flags = 0b1010; // 10 in decimal
// Bitwise operations
const READ = 0b001; // 1
const WRITE = 0b010; // 2
const EXEC = 0b100; // 4
const userPerms = READ | WRITE; // 0b011 = 3
const canRead = userPerms & READ; // truthy if READ bit is set
Hex uses 16 symbols: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15):
Hex: 0 1 2 3 4 5 6 7 8 9 A B C D E F
Dec: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
One hex digit = exactly 4 binary digits (nibble):
Hex F = binary 1111
Hex A = binary 1010
Hex FF = binary 11111111 = decimal 255
Colors: #2563eb = #25 (red=37) 63 (green=99) eb (blue=235)
Memory addresses: 0x7fff5fbff8b0
SHA-256 hashes: a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3
UUID: 550e8400-e29b-41d4-a716-446655440000
// Decimal to hex
(255).toString(16); // 'ff'
(255).toString(16).toUpperCase(); // 'FF'
// Hex to decimal
parseInt('ff', 16); // 255
parseInt('2563eb', 16); // 2450411
// Hex literal
const color = 0x2563eb; // 2450411
// Parse hex color to RGB
function hexToRgb(hex) {
const n = parseInt(hex.replace('#', ''), 16);
return { r: (n >> 16) & 0xff, g: (n >> 8) & 0xff, b: n & 0xff };
}
hexToRgb('#2563eb'); // { r: 37, g: 99, b: 235 }
Octal uses digits 0–7. Each octal digit represents exactly 3 binary bits — which maps perfectly to Unix file permission triplets (owner/group/world):
# Unix permissions
chmod 755 script.sh
# 7 = 111 (rwx) — owner has read, write, execute
# 5 = 101 (r-x) — group has read and execute
# 5 = 101 (r-x) — world has read and execute
chmod 644 config.json
# 6 = 110 (rw-) — owner has read, write
# 4 = 100 (r--) — group has read only
# 4 = 100 (r--) — world has read only
// Decimal to octal
(8).toString(8); // '10'
(255).toString(8); // '377'
// Octal to decimal
parseInt('755', 8); // 493
// Octal literals (prefix 0o)
const perms = 0o755; // 493
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 8 | 1000 | 10 | 8 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 255 | 11111111 | 377 | FF |
| 256 | 100000000 | 400 | 100 |
Use HeoLab's Base Converter to convert numbers between any bases — binary, octal, decimal, hex, and beyond — with step-by-step explanations.