Hexadecimal—or "hex" for short—is everywhere in programming. From web colors to memory addresses, MAC addresses to Unicode characters, understanding hex is essential for any developer.
What is Hexadecimal (Base-16)?
Hexadecimal is a number system that uses 16 digits instead of the 10 we use in everyday life (decimal) or the 2 computers use internally (binary).
The 16 digits are:
Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Hex: 0 1 2 3 4 5 6 7 8 9 A B C D E F
The letters A-F represent values 10-15. They can be uppercase or lowercase—FF and ff are the same.
Counting in Hex
Counting in hex works like decimal, but carries over at 16 instead of 10:
Decimal: 0, 1, 2, ... 9, 10, 11, ... 15, 16, 17, ... 255, 256
Hex: 0, 1, 2, ... 9, A, B, ... F, 10, 11, ... FF, 100
To convert hex to decimal, multiply each digit by powers of 16:
2F (hex) = 2×16¹ + F×16⁰ = 2×16 + 15×1 = 32 + 15 = 47 (decimal)
FF (hex) = 15×16 + 15×1 = 240 + 15 = 255 (decimal)
100 (hex) = 1×256 + 0×16 + 0×1 = 256 (decimal)
Why Hex is Useful for Computers
The magic of hex: each hex digit represents exactly 4 binary bits.
Hex: 0 1 2 3 4 5 6 7
Binary: 0000 0001 0010 0011 0100 0101 0110 0111
Hex: 8 9 A B C D E F
Binary: 1000 1001 1010 1011 1100 1101 1110 1111
This makes hex perfect for representing bytes:
- A byte is 8 bits
- 8 bits = 2 hex digits
- Much easier to read
FFthan11111111
Hex Colors in Web Development
The most common hex encounter for web developers: color codes.
color: #FF5733;
background-color: #3498DB;
A hex color breaks down into Red, Green, and Blue components:
#FF5733
││││││
RR GG BB
Red: FF = 255
Green: 57 = 87
Blue: 33 = 51
Each component ranges from 00 (0, none) to FF (255, maximum).
Common Colors
| Color | Hex | RGB |
|---|---|---|
| Black | #000000 | rgb(0, 0, 0) |
| White | #FFFFFF | rgb(255, 255, 255) |
| Red | #FF0000 | rgb(255, 0, 0) |
| Green | #00FF00 | rgb(0, 255, 0) |
| Blue | #0000FF | rgb(0, 0, 255) |
| Yellow | #FFFF00 | rgb(255, 255, 0) |
| Cyan | #00FFFF | rgb(0, 255, 255) |
| Magenta | #FF00FF | rgb(255, 0, 255) |
| Gray | #808080 | rgb(128, 128, 128) |
Shorthand Colors
When each component uses doubled digits, you can use 3-digit shorthand:
#FF5533 → #F53
#AABBCC → #ABC
#000000 → #000
The browser expands each digit: #F53 becomes #FF5533.
8-Digit Hex (with Alpha)
Modern browsers support alpha (transparency) in hex:
background: #FF573380; /* 50% transparent orange */
The last two digits are alpha: 00 (transparent) to FF (opaque).
Hex in Memory Addresses
Memory locations are shown in hex:
0x00000000 - Start of memory
0x7FFFFFFF - ~2GB mark
0xFFFFFFFF - 4GB (32-bit limit)
0xFFFFFFFFFFFFFFFF - 64-bit maximum
The 0x prefix indicates hexadecimal in most programming languages.
When debugging, you might see:
Segmentation fault at 0x0000000000401234
Stack pointer: 0x7FFE12345678
Hex makes these large numbers manageable.
Reading Hex Dumps
Hex dumps show file or memory contents in a readable format:
00000000: 4865 6c6c 6f20 576f 726c 640a Hello World.
00000010: 5468 6973 2069 7320 6120 7465 7374 This is a test
The left column shows the offset (position), the middle shows hex values, and the right shows ASCII representation. Non-printable characters appear as dots.
Converting Between Hex, Binary, and Decimal
Quick Mental Math
Hex to binary: Replace each hex digit with 4 bits
A3 → 1010 0011Binary to hex: Group bits by 4, convert each group
11110000 → F0Hex to decimal: Multiply by position values
2A → 2×16 + 10 = 42
In Code
// JavaScript
parseInt('FF', 16) // 255
(255).toString(16) // "ff"
// Python
int('FF', 16) # 255
hex(255) # '0xff'
format(255, 'x') # 'ff'
// C/C++
int x = 0xFF; // 255
printf("%X", 255); // FF
Hex in UUIDs and Hashes
UUIDs (Universally Unique Identifiers) are written in hex:
550e8400-e29b-41d4-a716-446655440000
Hash values are hex strings:
MD5: d41d8cd98f00b204e9800998ecf8427e
SHA-1: da39a3ee5e6b4b0d3255bfef95601890afd80709
SHA-256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Common Hex Values to Recognize
| Value | Decimal | Significance |
|---|---|---|
| 0x00 | 0 | Null, minimum byte |
| 0x0A | 10 | Line feed (LF) |
| 0x0D | 13 | Carriage return (CR) |
| 0x20 | 32 | Space |
| 0x30 | 48 | ASCII '0' |
| 0x41 | 65 | ASCII 'A' |
| 0x61 | 97 | ASCII 'a' |
| 0x7F | 127 | DEL, max ASCII |
| 0xFF | 255 | Maximum byte |
| 0xFFFF | 65535 | Max 16-bit |
| 0xDEADBEEF | 3735928559 | Debug marker |
| 0xCAFEBABE | 3405691582 | Java class file magic |
Programmers often use memorable hex values like DEADBEEF, CAFEBABE, FEEDFACE as markers or test values.
Hex in URLs and Encoding
URL encoding uses hex:
Space → %20
? → %3F
& → %26
The number after % is the hex ASCII value of the character.
Practical Tips
- Learn the powers of 16: 16, 256, 4096, 65536
- Memorize key values: FF=255, 80=128, 64=100 decimal
- Use programmer calculators: Most OS calculators have a programmer mode
- Read nibbles: Process hex 2 digits at a time (1 byte)
- Watch for the 0x prefix:
0x10is 16, not 10
Summary
Hexadecimal is the developer's number system:
- 16 digits: 0-9 and A-F
- Each digit = 4 binary bits
- Perfect for representing bytes compactly
- Used in colors, memory, hashes, UUIDs, and more
Once you're comfortable with hex, you'll see it everywhere—and wonder how you ever managed without it.
Need to convert hex values? Try our Hex Converter or Hex-RGB Color Converter!