Hexadecimal is a base-16 number system written with the digits 0-9 and letters A-F. Developers use it for byte values, memory addresses, colors, network identifiers, and file headers because each hex digit maps to four binary bits.
This guide explains positional notation, conversion to decimal and binary, and the prefixes that identify hex values in code. Use the hex calculator to check an answer while you work through the examples.
What Is Hexadecimal?
Hexadecimal, often shortened to "hex," is a base-16 number system.
In everyday life, you use the decimal system (base-10), which has ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. When you count past 9, you run out of single digits, so you carry over to the next position: 10, 11, 12, and so on. Each position represents a power of 10 (ones, tens, hundreds, thousands).
Hexadecimal uses sixteen symbols. The letters A through F provide the six values above 9:
Hex digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
- A = 10 (decimal)
- B = 11 (decimal)
- C = 12 (decimal)
- D = 13 (decimal)
- E = 14 (decimal)
- F = 15 (decimal)
Counting continues from 9 through A-F. The next value is hex 10, which equals decimal 16, followed by 11 through 1F, then 20.
Counting in Hexadecimal
The table compares decimal values 0 through 32 with their hex notation:
| Decimal | Hexadecimal | Decimal | Hexadecimal |
|---|---|---|---|
| 0 | 0 | 17 | 11 |
| 1 | 1 | 18 | 12 |
| 2 | 2 | 19 | 13 |
| 3 | 3 | 20 | 14 |
| 4 | 4 | 21 | 15 |
| 5 | 5 | 22 | 16 |
| 6 | 6 | 23 | 17 |
| 7 | 7 | 24 | 18 |
| 8 | 8 | 25 | 19 |
| 9 | 9 | 26 | 1A |
| 10 | A | 27 | 1B |
| 11 | B | 28 | 1C |
| 12 | C | 29 | 1D |
| 13 | D | 30 | 1E |
| 14 | E | 31 | 1F |
| 15 | F | 32 | 20 |
| 16 | 10 |
Hex carries to the next position after F, so decimal 16 is written as hex 10.
Why Developers Use Hexadecimal
Binary Notation
Digital systems store and process values as bits. Binary notation writes those values with 0 and 1. For example, decimal 255 is 11111111 in binary.
Long binary strings are difficult to scan. Consider this 16-bit value:
Binary: 1010001101011110
Comparing or transcribing this value requires counting bit positions.
Four-Bit Grouping
One hex digit represents exactly four binary digits, called a nibble. That fixed mapping makes conversion direct:
| Binary | Hex | Decimal |
|---|---|---|
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | A | 10 |
| 1011 | B | 11 |
| 1100 | C | 12 |
| 1101 | D | 13 |
| 1110 | E | 14 |
| 1111 | F | 15 |
The same value in hex is:
Binary: 1010001101011110
Hexadecimal: A37E
The two strings represent the same 16-bit value. Hex writes it with four digits instead of sixteen binary digits. This shorter notation does not compress the underlying data; it changes how the value is displayed.
Why Hex Maps Cleanly to Binary
Decimal digits do not align with fixed groups of bits. Hex-to-binary conversion works one nibble at a time:
- Split the binary into groups of four
- Convert each group to its hex equivalent
- Done
For example, the binary 11010110 becomes:
1101= D0110= 6- Result:
D6
Try that with decimal and you'll appreciate why programmers love hex.
How to Convert Between Number Systems
Understanding conversions solidifies your grasp of hexadecimal. Let's walk through the main scenarios.
Hexadecimal to Decimal
To convert hex to decimal, multiply each digit by 16 raised to its position (counting from right, starting at 0).
Example: Convert 2A3F to decimal
2A3F (hex) = ?
Position: 3 2 1 0
Hex digit: 2 A 3 F
Decimal: 2 10 3 15
Calculation:
(2 × 16³) + (10 × 16²) + (3 × 16¹) + (15 × 16⁰)
= (2 × 4096) + (10 × 256) + (3 × 16) + (15 × 1)
= 8192 + 2560 + 48 + 15
= 10,815 (decimal)
Or use our hex calculator for instant base conversion.
Decimal to Hexadecimal
Divide the decimal number by 16 repeatedly, keeping track of remainders. Read the remainders from bottom to top.
Example: Convert 254 to hex
254 ÷ 16 = 15 remainder 14 (E)
15 ÷ 16 = 0 remainder 15 (F)
Reading bottom-up: FE
So 254 (decimal) = FE (hex)
Hexadecimal to Binary
This is the easiest conversion. Replace each hex digit with its 4-bit binary equivalent.
Example: Convert 3C to binary
3 = 0011
C = 1100
Result: 00111100
You can drop leading zeros, so 3C = 111100 in binary.
Binary to Hexadecimal
Group binary digits into sets of four (from right to left), then convert each group.
Example: Convert 10111010 to hex
Split into groups of 4: 1011 1010
1011 = B
1010 = A
Result: BA
Real-World Applications of Hexadecimal
Hex appears in several common technical formats.
1. Color Codes
CSS colors such as #FF5733 use hexadecimal channel values.
The format is #RRGGBB:
- RR = Red intensity (00 to FF)
- GG = Green intensity (00 to FF)
- BB = Blue intensity (00 to FF)
Each color channel ranges from 0 (none) to 255 (full intensity). In hex, that's 00 to FF.
Example: #FF5733
- Red:
FF= 255 (maximum red) - Green:
57= 87 (moderate green) - Blue:
33= 51 (low blue) - Result: A vibrant orange-red
Pure colors are easy to spot:
#FF0000= pure red#00FF00= pure green#0000FF= pure blue#FFFFFF= white#000000= black
2. MAC Addresses
Network interfaces commonly use 48-bit MAC (Media Access Control) addresses written in hex. Example: A4:5E:60:E8:9B:2C
This address is displayed as six hex pairs. Vendor-assigned addresses use IEEE registration data, while locally administered addresses and modern privacy features may be generated or rotated; uniqueness is therefore a design goal, not a guarantee. See the IEEE Registration Authority for the authoritative assignment model.
3. Memory Addresses
When programs access computer memory, they use hexadecimal addresses. For example:
0x00400000 <- Memory location in hex
0x7FFF5A2C <- Another address
The 0x prefix indicates "this is hexadecimal." Memory dumps, debuggers, and low-level programming tools all display addresses in hex because it's compact and aligns perfectly with byte boundaries (2 hex digits = 1 byte).
4. Unicode Character Codes
Every encoded Unicode character is assigned a code point, conventionally written in hex. Some user-perceived characters are sequences of multiple code points. Examples:
U+0041= AU+03B1= α (Greek alpha)U+1F600= 😀 (grinning face emoji)
The U+ prefix means "Unicode code point in hexadecimal."
5. Assembly Language & Machine Code
Assembly programmers and reverse engineers work with hex constantly. Machine code instructions are represented in hex:
B8 05 00 00 00 MOV EAX, 5
Each byte (B8, 05, etc.) is in hex.
6. File Formats & Encoding
Many file formats begin with recognizable signatures:
- JPEG data commonly begins with
FF D8 FF - PNG data begins with
89 50 4E 47 0D 0A 1A 0A - A ZIP local-file header begins with
50 4B 03 04
The hex dump and file signature guide links these byte patterns to their format specifications. When you decode Base64 data, the result is a byte sequence that may be easier to inspect as hex than as text.
7. IP Addresses (IPv6)
IPv6 addresses are written in hexadecimal, like:
2001:0db8:85a3:0000:0000:8a2e:0370:7334
This is much more compact than trying to write 128 bits in decimal.
Common Hexadecimal Conventions
When you see hex in the wild, it often comes with special notation:
- 0x prefix:
0xABCD(common in C, JavaScript, Python) - # prefix:
#FF5733(HTML/CSS colors) - h suffix:
1A3Fh(assembly language) - \x escape:
\xA9(strings in programming) - U+ prefix:
U+00A9(Unicode)
These prefixes exist because hex digits (0-9, A-F) can be confused with decimal numbers or words. The 0x tells the computer "interpret this as hexadecimal, not decimal."
Hexadecimal in Programming
Most programming languages support hexadecimal literals. Here's how you'd use hex in popular languages:
Python:
color = 0xFF5733 # Hex literal
print(color) # Prints: 16734003 (decimal)
hex_string = hex(255) # Convert to hex string
print(hex_string) # Prints: 0xff
JavaScript:
let color = 0xFF5733;
console.log(color); // 16734003
console.log(color.toString(16)); // "ff5733"
C/C++:
int value = 0x2A; // Hex literal
printf("%d\n", value); // 42 (decimal)
printf("%X\n", value); // 2A (hex)
Tips for Working with Hexadecimal
-
Use a hex calculator: Don't do complex conversions by hand. Use the hex calculator for exact arithmetic and base conversion.
-
Memorize powers of 16: Knowing that 16¹=16, 16²=256, 16³=4096, 16⁴=65536 helps with mental estimation.
-
Practice pattern recognition: After a while, you'll recognize common values:
FF= 25580= 1287F= 127100= 256
-
Think in nibbles: Remember that each hex digit = 4 bits. Two hex digits = 1 byte. This makes conversions intuitive.
-
Use uppercase for clarity: While
0xabcdand0xABCDare identical, uppercase is often easier to distinguish from decimal.
Frequently Asked Questions
What does hexadecimal mean?
Hexadecimal means "base-16." The prefix "hexa-" comes from Greek meaning "six," and "decimal" means "ten," so hexadecimal literally means "six and ten" (sixteen). It's a number system that uses 16 distinct symbols: 0-9 and A-F.
Why do computers use hexadecimal?
Computers use hexadecimal because it provides a compact, human-readable way to represent binary data. One hex digit represents exactly four binary digits (bits), making conversion simple and reducing visual clutter. Instead of reading 16-digit binary sequences, programmers can read 4-character hex codes.
How do you convert hex to decimal?
To convert hexadecimal to decimal, multiply each hex digit by 16 raised to its position (starting from 0 on the right) and sum the results. For example, 1A in hex = (1 × 16¹) + (10 × 16⁰) = 16 + 10 = 26 in decimal. You can also use the hex calculator for exact base conversion.
What is the difference between binary, decimal, and hexadecimal?
Binary (base-2) uses only 0 and 1; decimal (base-10) uses 0-9; hexadecimal (base-16) uses 0-9 and A-F. Binary is how computers store data, decimal is what humans use daily, and hexadecimal bridges the gap by compactly representing binary in a human-readable format.
Where is hexadecimal used in real life?
Hexadecimal appears in CSS color codes (#FF5733), MAC addresses, memory addresses, Unicode code point notation (U+1F600), IPv6 addresses, and file signatures. It provides a shorter textual representation of binary values while preserving four-bit boundaries.
Is hexadecimal hard to learn?
Hexadecimal uses the same positional rules as decimal with sixteen symbols instead of ten. Learn A=10 through F=15 and group binary digits in fours; the remaining work is ordinary place-value arithmetic.
Can hexadecimal have decimals or fractions?
Yes. Hexadecimal can represent fractional values with a radix point. For example, hex 3.8 means (3 × 16⁰) + (8 × 16⁻¹) = 3.5 in decimal. Most file offsets, byte values, and addresses use whole numbers.
Summary
Hexadecimal shortens binary notation without changing the stored bits. Group binary digits in fours to convert them to hex, or expand each hex digit back to a four-bit group. The hex calculator handles larger base conversions and arithmetic checks.