Number Systems for Developers: Binary, Hex, and Octal
Number Systems for Developers: Binary, Hex, and Octal
Understanding number bases is essential for working with colors, permissions, bitwise operations, and low-level data.
The Four Common Bases
| Base | Name | Digits | Prefix |
|------|------|--------|--------|
| 2 | Binary | 0-1 | 0b |
| 8 | Octal | 0-7 | 0o |
| 10 | Decimal | 0-9 | (none) |
| 16 | Hexadecimal | 0-9, A-F | 0x |
Binary (Base 2)
Each digit (bit) is a power of 2: 1101 = 8 + 4 + 0 + 1 = 13.
Where You'll See It
Bitwise Operations in JavaScript
const READ = 0b100; // 4
const WRITE = 0b010; // 2
const EXEC = 0b001; // 1
const perms = READ | WRITE; // 0b110 = 6
const canRead = perms & READ; // truthy
Hexadecimal (Base 16)
Hex is compact binary: each hex digit represents exactly 4 bits. Two hex digits = one byte.
Where You'll See It
Quick Conversion
Binary: 1111 1010
Hex: F A = 0xFA = 250
Octal (Base 8)
Less common today but still used for Unix file permissions: chmod 755 means owner=7(rwx), group=5(r-x), others=5(r-x).
JavaScript Number Literals
const binary = 0b1010; // 10
const octal = 0o755; // 493
const hex = 0xFF; // 255
const decimal = 42;
Conversion in JavaScript
(255).toString(16) // "ff"
(255).toString(2) // "11111111"
(255).toString(8) // "377"
parseInt("ff", 16) // 255
parseInt("11111111", 2) // 255
Try It
Use our Number Base Converter to convert between binary, octal, decimal, and hexadecimal instantly.
Conclusion
Hex is the most practical alternative base for daily development — colors, hashes, and byte values. Binary matters for bitwise operations and networking. Octal is mainly for chmod.