Decimal to Hexadecimal Converter

Convert decimal numbers to hexadecimal (base 16) instantly. Enter a decimal number and get the hexadecimal equivalent instantly.

Padding:

Common Decimal to Hex Values

00x0
100xA
150xF
160x10
1000x64
1270x7F
1280x80
2550xFF
2560x100
10000x3E8
40960x1000
655350xFFFF

How to Convert Decimal to Hex

To convert a decimal number to hexadecimal manually, follow these steps:

  1. Divide the decimal number by 16
  2. Record the remainder (0-15, where 10-15 become A-F)
  3. Divide the quotient by 16 again
  4. Repeat until the quotient is 0
  5. 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.

Related Tools