Number Systems for Developers: Binary, Hex, and Octal
A practical guide to the four number systems developers encounter — how each works, where you'll see them in real code, and how to convert between them.
Why Developers Need Multiple Number Systems
Computers store everything as binary (base 2), but binary is verbose for humans to read. Different number systems exist because they map conveniently onto groups of bits: hexadecimal groups 4 bits, octal groups 3 bits. Understanding all four systems makes you significantly more effective when reading memory addresses, debugging bitwise operations, and working with permissions.
Decimal (Base 10)
The everyday number system. Each digit position represents a power of 10:
4096 = 4 × 10³ + 0 × 10² + 9 × 10¹ + 6 × 10⁰
= 4000 + 0 + 90 + 6You likely never think about this — it's just how numbers work. The other systems follow the exact same positional logic, just with a different base.
Binary (Base 2)
Only two digits: 0 and 1. Each position is a power of 2:
1011 (binary) = 1×8 + 0×4 + 1×2 + 1×1 = 11 (decimal)Where you see binary in practice
- Bitwise operations —
&,|,^,~,<<,>>all operate on bits - Bit flags — Packing multiple boolean states into a single integer:
const READ = 0b100, WRITE = 0b010, EXEC = 0b001 - Networking — Subnet masks, IP addresses, and CIDR notation
- Low-level protocols — Parsing binary file formats, image data, audio samples
Binary in JavaScript
// Literal: prefix 0b
const flags = 0b1010; // 10 in decimal
// Convert decimal to binary string
(255).toString(2); // "11111111"
// Parse binary string to decimal
parseInt('11111111', 2); // 255Hexadecimal (Base 16)
Digits 0–9 and A–F (or a–f). One hex digit represents exactly 4 bits, so two hex digits represent one byte (8 bits). This makes hex a compact, human-readable representation of binary data.
FF (hex) = 15×16 + 15 = 255 (decimal) = 11111111 (binary)
1A (hex) = 1×16 + 10 = 26 (decimal) = 00011010 (binary)Where you see hex in practice
- Colors —
#FF5733= R:255, G:87, B:51 - Memory addresses —
0x7ffee4b2c3a0 - Character encoding — Unicode code points:
U+1F600 - Hashes — MD5, SHA-256 output is hex-encoded binary
- UUIDs —
550e8400-e29b-41d4-a716-446655440000 - Network MACs —
00:1A:2B:3C:4D:5E
Hex in JavaScript
// Literal: prefix 0x
const addr = 0xFF; // 255
// Convert to hex string
(255).toString(16); // "ff"
(255).toString(16).toUpperCase(); // "FF"
// Parse hex string
parseInt('FF', 16); // 255
parseInt('0xFF', 16); // 255 — 0x prefix is handledOctal (Base 8)
Digits 0–7. Each octal digit represents exactly 3 bits. Octal was popular when computers had 6-bit bytes (three octal digits = 18 bits) but is now mostly encountered in one specific context.
Unix file permissions
The chmod command uses octal to set read (4), write (2), and execute (1) permissions for owner, group, and others:
chmod 755 file # 7=rwx (owner), 5=r-x (group), 5=r-x (others)
chmod 644 file # 6=rw- (owner), 4=r-- (group), 4=r-- (others)
# Each digit is a sum of:
# 4 = read, 2 = write, 1 = execute
# 7 = 4+2+1 = rwx
# 6 = 4+2 = rw-
# 5 = 4+1 = r-xOctal in JavaScript
// Literal: prefix 0o
const perm = 0o755; // 493 in decimal
// Convert to octal string
(493).toString(8); // "755"
// Parse octal string
parseInt('755', 8); // 493Quick Conversion Reference
Decimal | Binary | Octal | Hex
--------|-----------|-------|----
0 | 0000 | 0 | 0
8 | 1000 | 10 | 8
10 | 1010 | 12 | A
15 | 1111 | 17 | F
16 | 0001 0000 | 20 | 10
255 | 1111 1111 | 377 | FF
256 | 0001 0000 0000 | 400 | 100Converting in Your Head
Decimal → Hex: Divide repeatedly by 16, reading remainders bottom-up. Or group binary into 4-bit nibbles and convert each.
Hex → Binary: Replace each hex digit with its 4-bit binary equivalent directly — no arithmetic needed.
Binary → Octal: Group bits in threes from the right. Each group of 3 is one octal digit (0–7).
Convert between number bases instantly
Use our Number Base Converter to convert between binary, octal, decimal, and hex. Edit any field and the others update automatically.
Open Number Base Converter →