Binary, Hex, Octal: Number Systems Explained
Why We Count in Tens (And Computers Do Not)
Humans use the decimal system โ base 10 โ almost certainly because we have ten fingers. It is so natural to us that we rarely question it. But there is nothing mathematically special about the number 10. Any whole number greater than 1 can serve as the base of a number system.
Computers, however, are built from billions of tiny switches called transistors. Each transistor has two states: on or off, 1 or 0. This is why computers think in binary โ base 2. Everything your computer does, from displaying this text to streaming a video, ultimately reduces to long sequences of ones and zeros.
Binary: The Language of Machines
In binary, each digit (called a bit) represents a power of 2 rather than a power of 10.
The decimal number 42, for example, becomes 101010 in binary:
| Position | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|
| Bit | 1 | 0 | 1 | 0 | 1 | 0 |
That is: 32 + 8 + 2 = 42.
Binary is perfect for machines, but terrible for humans. Writing the number 255 requires eight digits (11111111). Larger numbers become unwieldy fast. Imagine trying to debug a program by staring at a wall of ones and zeros.
This is where hexadecimal comes in.
Hexadecimal: A Human-Friendly Shortcut
Hexadecimal (or simply hex) is base 16. It uses the digits 0 through 9 plus the letters A through F, where A = 10, B = 11, C = 12, D = 13, E = 14, and F = 15.
The beauty of hex is that each hex digit maps perfectly to exactly four binary digits (bits). This makes conversion between the two trivially easy:
| Hex | Binary |
|---|---|
| 0 | 0000 |
| 5 | 0101 |
| A | 1010 |
| F | 1111 |
The binary number 11111111 (decimal 255) becomes simply FF in hex. Much easier to read and write.
This is why hex is everywhere in computing:
- Colors in web design:
#FF5733represents a specific shade of orange-red. Each pair of hex digits encodes the red, green, and blue channels. - Memory addresses: Programmers reference memory locations using hex because it is compact and directly translates to binary.
- MAC addresses: The unique identifier for network devices (e.g.,
00:1A:2B:3C:4D:5E) is written in hex. - Unicode characters: The character U+00E9 (รฉ) is identified by its hex code point.
Octal: The Forgotten Middle Child
Octal is base 8, using digits 0 through 7. Each octal digit corresponds to exactly three binary digits.
Octal was popular in early computing when systems used word sizes that were multiples of three (like 12-bit or 36-bit architectures). Today, it is less common but survives in one important place: Unix file permissions.
When you run chmod 755 on a Linux file, you are using octal notation:
- 7 (binary 111) = read + write + execute for the owner
- 5 (binary 101) = read + execute for the group
- 5 (binary 101) = read + execute for everyone else
Each digit compactly encodes three permission flags โ a perfect use case for base 8.
Converting Between Systems
The principles are the same for any base. To convert a number from any base to decimal, multiply each digit by its positional value and add the results.
To convert from decimal to another base, repeatedly divide by the base and collect the remainders.
For example, converting decimal 100 to binary:
- 100 / 2 = 50 remainder 0
- 50 / 2 = 25 remainder 0
- 25 / 2 = 12 remainder 1
- 12 / 2 = 6 remainder 0
- 6 / 2 = 3 remainder 0
- 3 / 2 = 1 remainder 1
- 1 / 2 = 0 remainder 1
Reading the remainders from bottom to top: 1100100.
Why This Matters Beyond Programming
Understanding number systems is not just for software engineers. Digital artists work with hex colors daily. Network administrators read hex MAC addresses and IP configurations. Data analysts encounter binary flags in databases. Even understanding how file sizes work (why 1 KB is 1,024 bytes, not 1,000) requires a basic grasp of powers of 2.
Number systems are one of those foundational concepts that quietly underpin modern technology.
Want to try converting numbers between systems yourself? Use our Decimal to Binary Converter to see the math in action.
Fun Fact: The word โbitโ is a portmanteau of โbinary digit,โ coined by mathematician John Tukey in 1947. A group of 8 bits is called a โbyteโ โ a word playfully chosen to avoid confusion with โbit.โ