Base-16 (Hexadecimal) Number System
Hexadecimal is the bridge between human-readable and machine code. Essential for memory addresses, color codes, and making binary data more manageable.
What is Hexadecimal?
Hexadecimal (hex) is a base-16 number system that uses 16 distinct symbols: the numbers 0-9 and the letters A-F.
Decimal | Hex | Binary |
---|---|---|
0 | 0 | 0000 |
1 | 1 | 0001 |
2 | 2 | 0010 |
3 | 3 | 0011 |
4 | 4 | 0100 |
5 | 5 | 0101 |
6 | 6 | 0110 |
7 | 7 | 0111 |
8 | 8 | 1000 |
9 | 9 | 1001 |
(10) | A | 1010 |
(11) | B | 1011 |
(12) | C | 1100 |
(13) | D | 1101 |
(14) | E | 1110 |
(15) | F | 1111 |
Hexadecimal Notation
Hexadecimal numbers are often written with a prefix to distinguish them from decimal:
- 0x prefix:
0x2A
(programming languages like C, Python) - # prefix:
#FF0000
(web colors) - h suffix:
2Ah
(assembly language) - ₁₆ subscript:
2A₁₆
(mathematical notation)
Converting Hexadecimal to Decimal
Each position represents a power of 16:
Example: Convert 0x2F8 to decimal
16² (256) |
16¹ (16) |
16⁰ (1) |
---|---|---|
2 | F (15) | 8 |
2 × 256 = 512 | 15 × 16 = 240 | 8 × 1 = 8 |
Total: 512 + 240 + 8 = 760₁₀
Converting Decimal to Hexadecimal
Method: Division by 16
Example: Convert 1000₁₀ to hexadecimal
1000 ÷ 16 = 62 remainder 8 62 ÷ 16 = 3 remainder 14 (E) 3 ÷ 16 = 0 remainder 3 Read remainders from bottom to top: 3E8₁₆ or 0x3E8
Binary ↔ Hexadecimal Conversion
The beauty of hex: each hex digit represents exactly 4 binary digits!
Binary to Hex
Group binary digits in sets of 4 (from right to left) and convert each group:
Binary: 11010110 Group: 1101 0110 Hex: D 6 Result: 0xD6
Hex to Binary
Convert each hex digit to 4 binary digits:
Hex: 0xA3 Convert: A=1010, 3=0011 Result: 10100011
Hex | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
Hexadecimal in Cybersecurity
1. Memory Addresses
Memory addresses are displayed in hex for readability:
0x7FFE5C2A8B40 (instead of 140730365127488) 0x00400000 (typical base address for executables)
2. MAC Addresses
Network interface cards use 48-bit addresses in hex:
00:1B:44:11:3A:B7 00-1B-44-11-3A-B7 001B.4411.3AB7
3. Color Codes (Web/Graphics)
#FF0000 = Red (R:255 G:0 B:0) #00FF00 = Green (R:0 G:255 B:0) #0000FF = Blue (R:0 G:0 B:255) #FFFFFF = White (R:255 G:255 B:255) #000000 = Black (R:0 G:0 B:0)
4. Hex Editors & Forensics
Hex editors display file contents in hexadecimal:
Offset Hex ASCII 00000000 4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00 MZ.............. 00000010 B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ........@.......
5. Cryptographic Hashes
Hash functions output results in hexadecimal:
MD5: 5d41402abc4b2a76b9719d911017c592 SHA-1: aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d SHA-256: 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
Practice Exercises
Exercise 1: Hex to Decimal
Convert these hexadecimal numbers to decimal:
- 0xFF
- 0x100
- 0xCAFE
Exercise 2: Decimal to Hex
Convert these decimal numbers to hexadecimal:
- 255
- 1024
- 65535
Exercise 3: Binary to Hex
Convert these binary numbers to hexadecimal:
- 11111111
- 10101010
- 11000000101010000000000111111111
Exercise 4: Real-World Application
A memory dump shows the following bytes: 48 65 6C 6C 6F
. Using an ASCII table, decode this message.
Interactive Tools
Color Picker
Text to Hex
Next Steps
Now that you understand hexadecimal, explore how it's used in practice: