Binary, Decimal, and Hexadecimal: How to Convert Between Number Systems
Computers use binary (base 2) internally. Programmers often work with hexadecimal (base 16). Understanding these systems demystifies how computers store and display data.
The Three Systems
| System | Base | Digits Used | |--------|------|-------------| | Binary | 2 | 0, 1 | | Decimal | 10 | 0–9 | | Hexadecimal | 16 | 0–9, A–F |
In hex: A=10, B=11, C=12, D=13, E=14, F=15
Binary to Decimal
Each binary digit represents a power of 2, starting from the right.
Example: Convert 1101 (binary) to decimal
1×2³ + 1×2² + 0×2¹ + 1×2⁰
= 8 + 4 + 0 + 1
= 13
Decimal to Binary
Divide repeatedly by 2, recording remainders:
Example: Convert 25 to binary
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
Read remainders bottom to top: 11001
Check: 16 + 8 + 0 + 0 + 1 = 25 ✓
Hexadecimal to Decimal
Each hex digit represents a power of 16:
Example: Convert 2F (hex) to decimal
2×16¹ + F×16⁰
= 2×16 + 15×1
= 32 + 15
= 47
Binary to Hexadecimal (Quick Method)
Group binary digits in sets of 4 from the right, convert each group:
Example: 11010111 binary to hex
1101 = 13 = D
0111 = 7
Result: D7 hex
Why Hex?
8 binary digits (a byte) = exactly 2 hex digits. So:
- 00000000 = 00 (hex) = 0
- 11111111 = FF (hex) = 255
This makes hex a compact way to represent binary data. Web colors use hex (e.g., #FF5733 = red 255, green 87, blue 51).
Common Values
| Decimal | Binary | Hex | |---------|--------|-----| | 0 | 0000 | 0 | | 10 | 1010 | A | | 15 | 1111 | F | | 16 | 10000 | 10 | | 255 | 11111111 | FF | | 256 | 100000000 | 100 |
Use our Number Base Converter to convert between binary, decimal, hexadecimal, and octal instantly.