What is Hexadecimal? A Developer's Guide to Hex
Hexadecimal shows up everywhere in programming — from color codes to memory addresses to MAC addresses. Here's everything you need to know about the base-16 number system.
Table of Contents
What is Hexadecimal?
Hexadecimal (often shortened to hex) is a base-16 number system. While the decimal system we use daily has 10 digits (0–9), hexadecimal uses 16 symbols: the digits 0–9 plus the letters A–F.
The word comes from Greek hexa (six) and Latin decem(ten) — literally "six-ten," or sixteen.
In programming, hex values are typically prefixed with 0x to distinguish them from decimal numbers. For example, 0xFF is hexadecimal for 255 in decimal.
Why Do We Use Hexadecimal?
Computers operate in binary (base-2), but binary numbers get very long very quickly. The number 255, for instance, is 11111111 in binary — eight digits. In hex, it's simply FF.
Hex works so well with binary because 16 is a power of 2 (16 = 2⁴). This means:
- Each hex digit maps exactly to 4 binary digits (a nibble)
- Two hex digits represent exactly 1 byte (8 bits)
- Conversion between hex and binary is trivial — just group by 4
- It's far more compact and readable than raw binary
Hex gives us a human-friendly way to read and write binary data without losing the direct relationship to the underlying bits.
The 16 Hex Digits
Here's the complete hex digit table with decimal and binary equivalents:
| Hex | Decimal | 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 |
A | 10 | 1010 |
B | 11 | 1011 |
C | 12 | 1100 |
D | 13 | 1101 |
E | 14 | 1110 |
F | 15 | 1111 |
Note that A–F are case-insensitive — 0xff, 0xFF, and 0XFF all represent the same value.
How to Read Hex Numbers
Hex works just like decimal, except each position represents a power of 16 instead of 10:
Decimal place values: ... 1000 100 10 1
10³ 10² 10¹ 10⁰
Hex place values: ... 4096 256 16 1
16³ 16² 16¹ 16⁰
Example: 0x2F4
2 × 256 = 512
F × 16 = 240 (F = 15, so 15 × 16)
4 × 1 = 4
-----
Total = 756 (decimal)Converting Hex to Decimal
To convert hex to decimal, multiply each digit by its positional power of 16 and add the results:
Example: 0x1A3
1 × 16² = 1 × 256 = 256
A × 16¹ = 10 × 16 = 160
3 × 16⁰ = 3 × 1 = 3
-----
Result: 419
So 0x1A3 = 419 in decimal.Some common values worth memorizing:
0xFF= 255 (maximum value of one byte)0x100= 2560xFFFF= 65,535 (maximum 16-bit unsigned value)0x7FFFFFFF= 2,147,483,647 (maximum 32-bit signed integer)
Converting Decimal to Hex
To convert decimal to hex, repeatedly divide by 16 and record the remainders:
Example: Convert 750 to hex
750 ÷ 16 = 46 remainder 14 (E)
46 ÷ 16 = 2 remainder 14 (E)
2 ÷ 16 = 0 remainder 2 (2)
Read remainders bottom-to-top: 2EE
So 750 = 0x2EEHex and Binary
The real beauty of hex is how cleanly it maps to binary. Each hex digit is exactly 4 bits, so conversion is just grouping:
Hex to Binary:
0xA7 → A = 1010, 7 = 0111 → 10100111
Binary to Hex:
11011110 → 1101 = D, 1110 = E → 0xDE
Byte example:
0xFF → 11111111 (all bits on, max byte value)
0x00 → 00000000 (all bits off, zero)This is why hex is the preferred notation for viewing raw bytes — in hex dumps, memory viewers, and debuggers. Two hex characters always represent exactly one byte, making it easy to scan through binary data.
Hex in the Real World
Hexadecimal appears throughout computing and development:
CSS/HTML Colors
Colors are represented as 3 bytes — Red, Green, Blue — written in hex:
| Color | Hex Code | RGB Values | Preview |
|---|---|---|---|
| Red | #FF0000 | 255, 0, 0 | |
| Green | #00FF00 | 0, 255, 0 | |
| Blue | #0000FF | 0, 0, 255 | |
| White | #FFFFFF | 255, 255, 255 | |
| Black | #000000 | 0, 0, 0 |
Other Common Uses
- Memory addresses — Debuggers show addresses like
0x7FFF5FBFF8A0 - MAC addresses — Network hardware IDs like
00:1A:2B:3C:4D:5E - Unicode code points — Characters identified as
U+1F600(😀) - Error codes — Windows HRESULT codes like
0x80070005 - Cryptographic hashes — SHA-256, MD5 output is shown in hex
- IPv6 addresses — Written in hex:
2001:0db8:85a3::8a2e:0370:7334
Hex in Code
Every major programming language supports hex literals and conversion:
JavaScript
// Hex literals
const value = 0xFF; // 255
// Decimal to hex string
const hex = (255).toString(16); // "ff"
// Hex string to decimal
const dec = parseInt("ff", 16); // 255
// Pad to 2 digits (useful for colors)
const padded = (10).toString(16).padStart(2, "0"); // "0a"Python
# Hex literals
value = 0xFF # 255
# Decimal to hex string
hex_str = hex(255) # '0xff'
formatted = f"{255:02x}" # 'ff'
# Hex string to decimal
dec = int("ff", 16) # 255CSS
/* Full 6-digit hex */
color: #3B82F6;
/* Short 3-digit hex (each digit doubled) */
color: #FFF; /* same as #FFFFFF */
/* 8-digit hex with alpha transparency */
color: #3B82F680; /* 50% opacity */Common Hex Mistakes
A few pitfalls to watch out for:
❌ Confusing hex and decimal
10 in hex is 16 in decimal, not 10. Always use the 0x prefix or # to make it clear.
❌ Forgetting to pad with zeros
A byte should always be 2 hex digits. Writing A instead of 0A can cause parsing errors in some contexts.
❌ Using letters beyond F
Hex only uses A–F. Letters like G, H, or Z are not valid hex digits and will cause errors.
❌ Missing the # in CSS colors
CSS requires the # prefix for hex colors. FF0000 without # won't work.
Convert Hex Values Instantly
Use our free Hex Converter tool to convert between hexadecimal, decimal, binary, and octal — right in your browser with no data uploaded to any server.
Try Hex Converter →References
- Mozilla Developer Network. Hexadecimal — MDN Web Docs Glossary. https://developer.mozilla.org/en-US/docs/Glossary/Hexadecimal
- Mozilla Developer Network. <color> — CSS: Cascading Style Sheets. https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
- Mozilla Developer Network. parseInt() — JavaScript. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
- The Unicode Consortium. Unicode Code Charts. https://www.unicode.org/charts/
- IEEE. IEEE 802 — MAC Address Format. https://standards.ieee.org/products-programs/regauth/