If you've spent any time reading through assembly output, CSS colour values, UNIX permissions, or network documentation, you've run into number bases. Most developers get by just knowing that 0xFF means 255 — but understanding why unlocks a lot of the magic that happens at the hardware and protocol levels.
This is a short reference. Keep it bookmarked.
The four number systems you actually need
Decimal (base 10)
The one you grew up with. Ten digits: 0 through 9.
Every digit position represents a power of 10:
342 = 3×10² + 4×10¹ + 2×10⁰
= 300 + 40 + 2
Nothing surprising here.
Binary (base 2)
Two digits: 0 and 1. Every digit position represents a power of 2.
1011 (binary) = 1×2³ + 0×2² + 1×2¹ + 1×2⁰
= 8 + 0 + 2 + 1
= 11 (decimal)
Where you'll see it:
- Bitwise operations (
&,|,^,<<,>>) - Network masks (
/24 = 11111111.11111111.11111111.00000000) - Flags and permissions (
chmod 755— more on this below) - Low-level debugging, registers, microcontrollers
Quick rule: the highest value of an n-bit number is 2ⁿ - 1. An 8-bit byte tops out at 255.
Hexadecimal (base 16)
Sixteen digits: 0–9, then A–F (where A=10, B=11, ..., F=15). Each hex digit represents exactly 4 binary bits, which makes hex a compact shorthand for binary.
0xFF = 1111 1111 (binary) = 255 (decimal)
0x1A = 0001 1010 (binary) = 26 (decimal)
Where you'll see it:
- HTML/CSS colours:
#2F855A= R:0x2F G:0x85 B:0x5A - Memory addresses:
0x7fff5fbff8b0 - SHA-256 and MD5 hashes:
5d41402abc4b2a76b9719d911017c592 - UTF-8 escape sequences:
A= "A" - MAC addresses:
00:1A:2B:3C:4D:5E - File headers (magic bytes):
89 50 4E 47= PNG
One hex digit = 4 bits = one nibble. Two hex digits = 1 byte = 8 bits. This is why hex values always appear in pairs in memory dumps.
Octal (base 8)
Eight digits: 0 through 7. Less common today, but you encounter it every time you use chmod.
chmod 755 myfile
That 755 is octal:
7 = 111 binary = read(4) + write(2) + execute(1) → owner: full access
5 = 101 binary = read(4) + execute(1) → group: read + execute
5 = 101 binary = read(4) + execute(1) → others: read + execute
Each octal digit maps directly to 3 binary bits — which is why it was popular on 12-bit and 36-bit machines before 16-bit architectures made hex the standard.
In code, octal literals are prefixed with 0 in C/C++/JavaScript:
console.log(0755); // 493 in decimal (legacy syntax)
Conversion cheat sheet
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 8 | 0000 1000 | 10 | 8 |
| 10 | 0000 1010 | 12 | A |
| 15 | 0000 1111 | 17 | F |
| 16 | 0001 0000 | 20 | 10 |
| 32 | 0010 0000 | 40 | 20 |
| 64 | 0100 0000 | 100 | 40 |
| 127 | 0111 1111 | 177 | 7F |
| 128 | 1000 0000 | 200 | 80 |
| 255 | 1111 1111 | 377 | FF |
Mental shortcuts that actually stick
Hex to decimal fast: Split into two nibbles, multiply the left by 16, add the right.
0xB4 = 11×16 + 4 = 176 + 4 = 180
Is a hex colour light or dark? If both R, G, B values are above 0x88 (136), it's a light colour. Below 0x44 (68) is very dark.
Binary shifts = powers of 2:
n << 1 doubles n. n >> 1 halves it (integer).
Useful for performance tricks and flags.
Octal digits = 3 bits each, Hex digits = 4 bits each. This is why UNIX permissions use three octal digits (3 actors × 3 permission bits = 9 bits total).
Converting quickly in the browser
If you need to convert between bases without pulling up a terminal, a free browser-based tool does all four at once:
Number Base Converter — snappytools.app
Type in any field (binary, octal, decimal, or hex) and all others update live. Handles arbitrary-precision integers using JavaScript's BigInt, so SHA-256 hash values won't overflow.
In JavaScript
// Decimal → other bases
(255).toString(2) // "11111111" (binary)
(255).toString(8) // "377" (octal)
(255).toString(16) // "ff" (hex)
// Other bases → decimal
parseInt("11111111", 2) // 255
parseInt("377", 8) // 255
parseInt("ff", 16) // 255
// Hex literals
0xFF // 255
0o377 // 255 (modern octal syntax — note lowercase 'o')
0b11111111 // 255 (binary literal — ES2015+)
Number bases are one of those fundamentals that pay dividends every time you read a stack trace, configure a firewall rule, or decode a protocol. Fifteen minutes with the conversion table above and it clicks permanently.
SnappyTools builds free, fast, browser-based tools for developers and designers. No signup, no data uploaded.
Top comments (0)