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
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
(10)A1010
(11)B1011
(12)C1100
(13)D1101
(14)E1110
(15)F1111
Why Hexadecimal? One hex digit represents exactly 4 bits (a nibble), making it perfect for representing binary data compactly. Two hex digits represent one byte.

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)
Case Insensitive: Hex letters can be uppercase (A-F) or lowercase (a-f). Both 0xFF and 0xff are the same value.

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
                    
Verification: 3×256 + 14×16 + 8×1 = 768 + 224 + 8 = 1000 ✓

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 01234567 89ABCDEF
Binary 0000000100100011 0100010101100111 1000100110101011 1100110111101111

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)
                            
#FF0000
#00FF00
#0000FF
#FFFFFF
#000000
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:

  1. 0xFF
  2. 0x100
  3. 0xCAFE
Exercise 2: Decimal to Hex

Convert these decimal numbers to hexadecimal:

  1. 255
  2. 1024
  3. 65535
Exercise 3: Binary to Hex

Convert these binary numbers to hexadecimal:

  1. 11111111
  2. 10101010
  3. 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: