Hexadecimal Numbers: Conversion to Decimal and Binary
Hexadecimal (base-16) is a compact and efficient number system widely used in computing, networking, and low-level programming. Unlike binary (base-2), which can be cumbersome for humans to read, hexadecimal simplifies the representation of large binary values by grouping them into 4-bit segments (nibbles). This guide explains how to convert hexadecimal digits to decimal and binary, their practical applications, and key rules for accurate conversions.
Key Points
- Hexadecimal (base-16) uses digits
0–9and lettersA–Fto represent values0–15. - One hex digit = 4 bits (nibble), making it ideal for compact binary representation.
- Conversion rules:
- Hex → Decimal: Replace letters (
A–F) with their decimal equivalents (10–15). - Hex → Binary: Replace each hex digit with its 4-bit binary equivalent (zero-padded).
- Hex → Decimal: Replace letters (
- Practical uses: MAC addresses, memory addresses, and low-level networking (OSI Layer 2).
- Common pitfalls: Forgetting zero-padding, misinterpreting letters as characters, or exceeding
F.
Why Use Hexadecimal?
Binary numbers grow unwieldy quickly (e.g., 11010110 for 214). Hexadecimal solves this by:
- Compactness: 1 hex digit = 4 bits (e.g.,
D6=11010110). - Readability: Easier to parse than long binary strings.
- Alignment: Matches byte boundaries (2 hex digits = 1 byte = 8 bits).
Example: A MAC address like
00:1A:2Bis far more readable than its binary equivalent (00000000 00011010 00101011).
Hexadecimal Basics
Digits and Values
Hexadecimal extends decimal with letters to represent values 10–15:
| Hex | Decimal | Binary |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| ... | ... | ... |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
Key Rule: The maximum hex digit (
F) equals15in decimal and1111in binary.
Conversion Methods
Hexadecimal to Decimal
- Replace letters (
A–F) with their decimal values (10–15). - For multi-digit hex numbers, use positional notation (e.g.,
1A=1×16 + 10 = 26).
Examples:
A=101F=1×16 + 15 = 31FF=15×16 + 15 = 255
Hexadecimal to Binary
Replace each hex digit with its 4-bit binary equivalent (zero-padded):
Example:
Hex: 3 A F 2
Bin: 0011 1010 1111 0010
Result: 3AF2₁₆ = 0011101011110010₂.
Why 4 bits? The maximum hex digit (
F) requires 4 bits (1111). Zero-padding ensures consistency (e.g.,1=0001).
Practical Applications
MAC Addresses
MAC addresses (OSI Layer 2) are 48-bit identifiers written in hexadecimal, separated by colons or hyphens:
00:1A:2B:3C:4D:5E
- Each pair = 1 byte (8 bits).
- Example:
1A=00011010₂.
Memory Addresses
Hexadecimal simplifies memory addressing in programming (e.g., 0x7FFF in C/C++).
Common Mistakes
- Ignoring zero-padding: Writing
1as1instead of0001in binary. - Misinterpreting letters: Treating
Aas a character, not the value10. - Exceeding
F: Hex digits cannot go beyondF(e.g.,Gis invalid). - Byte misalignment: Forgetting that 2 hex digits = 1 byte.
Quick Reference
Hex → Binary Cheat Sheet
| Hex | Binary |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
| 9 | 1001 |
| A | 1010 |
| B | 1011 |
| C | 1100 |
| D | 1101 |
| E | 1110 |
| F | 1111 |
Learn More
- OSI Model: How hexadecimal fits into Layer 2 (Data Link) networking.
- Endianness: Byte order in hexadecimal representations (e.g.,
0x1234vs.0x3412). - Color Codes: Hexadecimal in web design (e.g.,
#FFFFFFfor white).