Binary (base 2) uses only 0 and 1. Hexadecimal (base 16) uses 0–9 plus A–F. The key relationship: one hex digit always equals exactly 4 binary digits (bits), so one byte = 2 hex digits. Programmers choose hex because it is far more compact while remaining directly convertible to binary without arithmetic.
The Two Alphabets Side by Side
| 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 |
Once you memorize this table, you can translate between binary and hex by inspection — no division required.
Converting a Byte: Binary to Hex
Take the byte 01000001 (the letter A in ASCII, decimal 65).
- Split into two nibbles (groups of 4):
0100and0001. - Convert each nibble:
0100= 4,0001= 1. - Write the hex digits:
41.
So 65 in decimal = 01000001 in binary = 41 in hex. You can verify with the hex converter.
A more complex example: the byte 11111111 (decimal 255).
- Left nibble
1111= F - Right nibble
1111= F - Result:
FF
That is why 0xFF appears in code as the maximum single-byte value.
Where Each Format Appears
| Format | Typical use |
|---|---|
| Binary | Circuit design, boolean logic, low-level bit ops |
| Hexadecimal | Memory addresses, color codes (#FF5733), file dumps |
| Decimal | Human-facing numbers and counts |
Web colors use 6-digit hex: #RRGGBB. The color #FF0000 is pure red — red channel at 255 (FF), green at 0, blue at 0.
Unicode code points are written in hex. The letter A is U+0041 (hex 41, decimal 65). The euro sign is U+20AC (hex 20AC, decimal 8364).
Converting Hex Back to Binary
Each hex digit expands to exactly 4 bits:
A= 1010F= 11110= 0000
So AF in hex = 1010 1111 in binary = 175 in decimal.
No intermediate decimal step is needed. That direct mapping is why hex exists — it is shorthand binary, nothing more.
When to Use Which
Use binary when you need to inspect or manipulate individual bits — checking flags, writing bitmasks, or understanding how data is physically stored.
Use hex when you are reading memory dumps, writing color values, specifying Unicode code points, or working with byte streams where visual compactness matters.
Use decimal for everything a human normally counts or measures.
Octal: A Third System Worth Knowing
Hexadecimal has largely replaced octal (base 8) in modern computing, but you still encounter octal in Unix file permissions. The permission mask 0755 is an octal number: the leading zero signals octal in C, Python 2, and several shell environments. Each octal digit represents exactly 3 bits (not 4), so converting between octal and binary is also direct — just a smaller grouping.
| Octal | Binary | Decimal |
|---|---|---|
| 0 | 000 | 0 |
| 1 | 001 | 1 |
| 7 | 111 | 7 |
Unix permission rwxr-xr-x in binary is 111 101 101 = octal 755. Once you see the three-bit grouping, permission math becomes mechanical.
Practical Cheat Sheet
| Task | Best format |
|---|---|
| Reading a file’s bytes in a hex editor | Hex |
| Checking a network bitmask | Binary |
| Writing a CSS color | Hex (#RRGGBB) |
| Setting Unix permissions | Octal |
| Any normal human math | Decimal |
Hex editors show files as two-column pairs of hex digits (one byte each) alongside an ASCII interpretation on the right. When you see 48 65 6C 6C 6F, you know the byte values are 72, 101, 108, 108, 111 — the ASCII codes for “Hello”. Converting those two-digit hex pairs to binary mentally (4 bits per digit) takes seconds with the table above memorized.
See How to Read Binary for a full positional breakdown, or Bits and Bytes Explained to understand how these units group together in real systems.