Binary, Hexadecimal, and Decimal: Why Programmers Need to Master All Three Number Systems
Published: July 8, 2025 · 6 min read
If you grew up counting on ten fingers, you were raised on decimal — base 10. It's the number system we use for prices, measurements, and just about everything in daily life. But step into programming and suddenly you're staring at 0xFF5733 in your CSS, 0b11010101 in your bitwise operations, and chmod 755 on the command line. Different contexts demand different number systems, and fluency in all three is one of those skills that separates programmers who are perpetually confused from those who feel at home in the code.
Let's build that fluency from the ground up.
Decimal (Base 10): The Familiar Friend
Decimal uses ten digits (0–9). Each position represents a power of 10. The number 253 in decimal means: (2 × 10²) + (5 × 10¹) + (3 × 10⁰) = 200 + 50 + 3 = 253. This is second nature to most of us, but explicitly understanding positional notation is the foundation for every other number system. In programming, decimal is the default: when you write let count = 42, you're using decimal. When you log a number to the console, it prints in decimal. It's the universal human-readable format.
Binary (Base 2): The Language of Computers
Binary uses only two digits: 0 and 1. Each position represents a power of 2. The number 10110 in binary means: (1 × 2⁴) + (0 × 2³) + (1 × 2²) + (1 × 2¹) + (0 × 2⁰) = 16 + 0 + 4 + 2 + 0 = 22 in decimal.
Why does binary matter? Because at the hardware level, computers are built from transistors that are either on (1) or off (0). Every image you see, every video you stream, every database query you run — it all decomposes to binary. In programming, binary shows up in several concrete ways:
- Bitwise operations: Operators like
&(AND),|(OR),^(XOR),~(NOT),<<(left shift), and>>(right shift) manipulate individual bits. They're essential for performance-critical code, embedded systems, and low-level protocols. - Bit flags: Instead of storing eight separate boolean values, you can pack them into a single byte where each bit represents an on/off state. This is how Unix file permissions work: read (4), write (2), execute (1).
chmod 755sets owner=rwx (4+2+1=7), group=r-x (4+0+1=5), others=r-x (4+0+1=5). - Data representation: Understanding binary helps you grasp why a
uint8stores values from 0 to 255 (2⁸ − 1), why integer overflow wraps around, and why floating-point numbers sometimes behave oddly.
Hexadecimal (Base 16): The Programmer's Shorthand
Hexadecimal uses sixteen digits: 0–9 followed by A–F (where A=10, B=11, C=12, D=13, E=14, F=15). Each position represents a power of 16. The number 2F in hex means: (2 × 16¹) + (F × 16⁰) = 32 + 15 = 47 in decimal.
The magic of hex is its relationship to binary: one hex digit represents exactly four binary digits (a nibble). This makes hex a compact, human-friendly way to express binary values. The conversion is mechanical once you memorize the 16 mappings:
| Decimal | Binary | Hex |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
To convert a binary number to hex, group the bits into sets of four (from the right) and look up each group. For example: 11111111 in binary groups as 1111 1111, which is F F → FF in hex → 255 in decimal. That's why the maximum value of a single byte is 0xFF = 255. It's also why CSS color channels range from 0–255: each channel is one byte.
Practical Scenarios Every Developer Encounters
CSS Colors
Hex color codes like #FF5733 are three pairs of hex values: FF (red = 255), 57 (green = 87), 33 (blue = 51). Understanding this structure lets you mentally estimate colors: #FF0000 is pure red, #00FF00 is pure green, #888888 is medium gray (equal mid-range values). When you see #FFFFFF, you know it's maximum of every channel: white. #000000 is the absence of all color: black.
Unix File Permissions
We touched on this earlier, but it deserves emphasis: chmod permissions are octal (base 8), not decimal — but they represent three groups of three bits. chmod 644 is: owner read+write (110 binary = 6), group read (100 = 4), others read (100 = 4). In binary: 110 100 100. The relationship between octal, binary, and the familiar rwx notation becomes intuitive with practice.
Network Masks and IP Addresses
Subnet masks like 255.255.255.0 are easier to understand in binary: 11111111.11111111.11111111.00000000. The 24 ones followed by 8 zeros is why this mask is written as /24 in CIDR notation. IPv6 addresses use hex extensively: 2001:0db8:85a3::8a2e:0370:7334.
Memory Addresses
When debugging with tools like GDB or examining crash dumps, memory addresses are displayed in hex: 0x7fff5fbff840. The 0x prefix is the universal convention for "this is a hexadecimal number." If you see 0b it's binary, and 0o (or just a leading zero in older languages) indicates octal.
Master the Conversions
The best way to build fluency is practice. Try these manually, then verify with a converter:
- Decimal 42 → Binary? (Answer:
101010) - Binary
10101100→ Hex? (Answer:AC) - Hex
3E8→ Decimal? (Answer: 1000) - Decimal 255 → Hex? (Answer:
FF)
Our free Number Base Converter handles conversions between binary, octal, decimal, and hexadecimal instantly. Bookmark it as your go-to reference when you need to double-check a conversion or explore how a number looks across all four bases simultaneously.
Number systems are one of those topics that seems abstract until you use them daily. Give it a few weeks of conscious practice — reading hex color codes, mentally converting small binary values, checking file permissions — and it becomes as natural as counting to ten.