What is Hexadecimal?
Hexadecimal (often called "hex") is a base-16 number system that uses sixteen digits: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15). The name comes from Greek "hex" (six) and Latin "decem" (ten).
Hexadecimal is extremely useful in computing because it's a compact way to represent binary numbers. Each hexadecimal digit represents exactly four binary digits (bits), making conversions between binary and hex straightforward. Hex provides a human-friendly way to work with binary data.
Hexadecimal digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F
You've probably seen hexadecimal in web color codes (like #FF0000 for red) or in programming when looking at memory addresses. Understanding hex is essential for anyone working with computers at more than a basic level.
How to Convert Decimal to Hexadecimal
Converting decimal to hexadecimal uses the division-by-16 method. The key difference from other bases is handling remainders 10-15, which become letters A-F:
- Start with your decimal number - Let's convert 300 to hexadecimal
- Divide by 16 - 300 ÷ 16 = 18 with remainder 12
- Convert remainder to hex - Remainder 12 becomes C in hexadecimal
- Write down the hex remainder - C becomes the rightmost digit
- Divide the quotient by 16 - Take 18 and divide by 16: 18 ÷ 16 = 1 remainder 2
- Write down this remainder - 2 becomes the next digit to the left
- Repeat until quotient is less than 16 - Keep dividing until quotient is less than 16
- The last quotient becomes the leftmost digit - When quotient is less than 16, convert it to hex if needed
- Read from bottom to top - The hex number is read from last quotient to first remainder
Complete example: Convert 300 to hexadecimal
300 ÷ 16 = 18 remainder 12 (C in hex)
18 ÷ 16 = 1 remainder 2
1 is less than 16, so we stop here
Hexadecimal result: Read from last quotient to first remainder: 12C
So 300 in decimal = 12C in hexadecimal
Our converter handles all these steps automatically, including converting numbers 10-15 to letters A-F.
Where You See Hexadecimal
Hexadecimal appears in many areas of technology:
- Web Design - Color codes in HTML/CSS use hexadecimal (#RRGGBB format)
- Programming - Memory addresses, error codes, and debug output often use hex
- Networking - MAC addresses for network devices (like 00:1A:2B:3C:4D:5E)
- File Formats - Some file headers contain "magic numbers" in hexadecimal
- Character Encoding - Unicode character codes (like U+0041 for 'A')
- Assembly Language - Low-level programming often uses hex constants
- Digital Electronics - Engineers use hex when working with hardware
Next time you see a color code or a strange code with letters and numbers, it's probably hexadecimal!
Hexadecimal Color Codes
One of the most common uses of hexadecimal is in web color codes. Colors on the web are specified using a # followed by six hexadecimal digits:
How web colors work
Format: #RRGGBB
RR = Red component (00 to FF, or 0 to 255 in decimal)
GG = Green component (00 to FF, or 0 to 255 in decimal)
BB = Blue component (00 to FF, or 0 to 255 in decimal)
Example: #FF0000 = Full red, no green, no blue = Red
| Color | Hexadecimal | Decimal (R,G,B) |
|---|---|---|
| Red | #FF0000 | 255, 0, 0 |
| Green | #00FF00 | 0, 255, 0 |
| Blue | #0000FF | 0, 0, 255 |
| Yellow | #FFFF00 | 255, 255, 0 |
| Magenta | #FF00FF | 255, 0, 255 |
| Cyan | #00FFFF | 0, 255, 255 |
| White | #FFFFFF | 255, 255, 255 |
| Black | #000000 | 0, 0, 0 |
Try converting these decimal RGB values to hexadecimal using our converter!
Common Decimal to Hexadecimal Conversions
Here are important decimal numbers and their hex equivalents:
| Decimal | Hexadecimal | What It Represents |
|---|---|---|
| 0 | 0 | Zero in all bases |
| 10 | A | First letter in hex |
| 15 | F | Largest single hex digit |
| 16 | 10 | First "carry" in hex |
| 255 | FF | Maximum 8-bit value, white in web colors |
| 256 | 100 | One more than max 8-bit value |
| 4096 | 1000 | 16 cubed (16³) |
| 65535 | FFFF | Maximum 16-bit value |
| 16777215 | FFFFFF | Maximum 24-bit value, white in 24-bit color |
Hexadecimal in Programming
Programmers use hexadecimal extensively because:
- Memory Addresses - Computer memory locations are often shown in hexadecimal
- Bit Masks - Hex makes it easy to work with specific bits (each hex digit = 4 bits)
- Debugging - Debuggers often show data in hexadecimal
- Constants - Programmers use hex for constants (like 0xFF for 255)
- Color Values - Graphics programming uses hex for colors
- Network Programming - Network addresses and ports sometimes use hex
Hexadecimal in C/C++/Java
In these languages, hex numbers start with 0x:
0xFF = 255 in decimal
0x10 = 16 in decimal
0x1A = 26 in decimal (1×16 + 10)
0xDEADBEEF = 3,735,928,559 in decimal (a famous debug value)