Understanding Hexadecimal Numbers
Hexadecimal (hex) is a base-16 number system using digits 0-9 and letters A-F. Each hex digit represents exactly 4 binary bits, making it the preferred format for representing binary data in a human-readable form. Programmers use hex extensively for memory addresses, color codes, and low-level programming.
Hex Digit Values
A=10, B=11, C=12, D=13, E=14, F=15
Example: FF = 15×16 + 15 = 255 in decimal
Hex Conversion Reference
| Hex | Dec | Binary | Hex | Dec | Binary |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 8 | 8 | 1000 |
| 1 | 1 | 0001 | 9 | 9 | 1001 |
| 2 | 2 | 0010 | A | 10 | 1010 |
| 3 | 3 | 0011 | B | 11 | 1011 |
| 4 | 4 | 0100 | C | 12 | 1100 |
| 5 | 5 | 0101 | D | 13 | 1101 |
| 6 | 6 | 0110 | E | 14 | 1110 |
| 7 | 7 | 0111 | F | 15 | 1111 |
Common Uses of Hexadecimal
Web Color Codes
HTML/CSS colors use 6-digit hex codes (#RRGGBB) where each pair represents red, green, and blue intensity (00-FF = 0-255):
- #FF0000 = Red
- #00FF00 = Green
- #0000FF = Blue
- #FFFFFF = White
- #000000 = Black
Memory Addresses
Computer memory locations are expressed in hex (e.g., 0x7FFF0000) because it directly corresponds to binary while being much shorter to write.
MAC Addresses
Network hardware addresses use hex notation (e.g., 00:1A:2B:3C:4D:5E) for their 48-bit identifiers.
How to Convert Hex to Decimal
Example: Convert 2A3 to decimal
2×16² + A×16¹ + 3×16⁰
= 2×256 + 10×16 + 3×1
= 512 + 160 + 3 = 675
Frequently Asked Questions
What does 0x mean before hex numbers?
The "0x" prefix indicates hexadecimal notation in programming languages like C, Java, and Python. It distinguishes hex values from decimal (e.g., 0x10 = 16, not 10).
Why is hex preferred over binary in programming?
Each hex digit maps to exactly 4 binary bits, making conversion trivial. A byte (8 bits) is always 2 hex digits. This makes hex compact while maintaining a direct relationship to binary.