Decimal to Hexadecimal Converter
Convert decimal numbers to hexadecimal (base 16) instantly. Enter a decimal number and get the hexadecimal equivalent instantly.
Common Decimal to Hex Values
How to Convert Decimal to Hex
To convert a decimal number to hexadecimal manually, follow these steps:
- Divide the decimal number by 16
- Record the remainder (0-15, where 10-15 become A-F)
- Divide the quotient by 16 again
- Repeat until the quotient is 0
- Read the remainders in reverse order
Example: Convert 255 to hex:
- 255 ÷ 16 = 15 remainder 15 (F)
- 15 ÷ 16 = 0 remainder 15 (F)
- Result: FF (reading remainders in reverse)
Code Examples
const decimal = 255;
const hex = decimal.toString(16); // "ff"
const hexUpper = decimal.toString(16).toUpperCase(); // "FF"
const padded = decimal.toString(16).padStart(4, '0'); // "00ff"Frequently Asked Questions
How do I convert decimal to hex?
Divide the decimal number by 16 repeatedly, noting the remainders. Read the remainders in reverse order, converting values 10-15 to A-F. For example, 255 ÷ 16 = 15 remainder 15, giving FF in hex.
What is hexadecimal used for?
Hexadecimal is widely used in programming for memory addresses, color codes (#FF5733), byte values, and anywhere binary data needs compact representation. Each hex digit represents exactly 4 bits.
Should I use uppercase or lowercase hex?
Both are valid. Convention varies: CSS colors often use lowercase (#ff5733), while memory addresses typically use uppercase (0xFF). Pick one style and be consistent in your project.