Binary and Hex Represent the Same Data
Binary and hexadecimal are two ways to write numbers. Binary uses base 2, with digits 0 and 1. Hexadecimal uses base 16, with digits 0 through 9 and letters A through F.
Computers store data as bits, so binary is the most direct representation. Humans often use hexadecimal because it is much shorter and maps cleanly to binary.
Four Bits Equal One Hex Digit
One hex digit represents exactly four bits:
| Binary | Hex |
|---|---|
| 0000 | 0 |
| 0001 | 1 |
| 0010 | 2 |
| 0011 | 3 |
| 0100 | 4 |
| 0101 | 5 |
| 1010 | A |
| 1111 | F |
This clean mapping is why hex is so common in programming.
Byte Example
The binary byte 01001000 can be split into two nibbles:
0100 1000
0100 is hex 4, and 1000 is hex 8, so the byte is 0x48. In decimal, that is 72. In ASCII, 72 is H.
Why Hex Is Easier to Read
A 32-bit value in binary is long:
11011110101011011011111011101111
The same value in hex is:
DEADBEEF
Hex preserves bit-level accuracy while reducing visual noise.
Where Hexadecimal Appears
Hex is used in many practical contexts:
- CSS colors:
#10B981 - Memory addresses:
0x7ffee3b8 - Byte dumps and packet captures.
- Unicode code points:
U+00E9 - Hashes and checksums.
- Binary file signatures.
Binary is still useful when you need to inspect individual flags, masks, or bit fields.
Converting Hex to Binary
Convert each hex digit to its 4-bit binary value:
A7 = 1010 0111
A is 1010; 7 is 0111. The result is 10100111.
Converting Binary to Hex
Group bits from right to left in groups of four. Add leading zeros if needed:
101101 = 0010 1101 = 2D
This is faster than converting through decimal.
Binary for Flags, Hex for Dumps
Binary is best when each bit has meaning. For example, a permission mask might use one bit for read, one for write, and one for execute.
Hex is best when reading many bytes. Packet dumps, file headers, and cryptographic hashes are too long to display comfortably in binary.
Frequently Asked Questions
Is hex closer to the computer than decimal?
Hex is not how the computer stores data internally; the computer stores bits. Hex is a human-friendly shorthand for those bits.
Why does hex use A to F?
Base 16 needs six symbols beyond 0 through 9. The letters A, B, C, D, E, and F represent decimal values 10 through 15.
Is a hex string smaller than binary?
As text, yes. One hex digit represents four binary digits, so hex notation is one quarter the length of binary notation.