How to Convert Decimal to Hexadecimal
Hexadecimal is base 16. Divide by 16 repeatedly and read the remainders backwards.
Updated
Try it now: Decimal to Hex Converter. It runs in your browser, with no signup.
The digits
Base 16 needs sixteen symbols, so after 9 it continues with the letters A to F.
Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hex: 0 1 2 3 4 5 6 7 8 9 A B C D E F
Method: repeated division
Divide the number by 16, write down the remainder, then divide the quotient by 16 again. Stop when the quotient is 0. The hex number is the remainders read from last to first.
3054 / 16 = 190 remainder 14 (E) 190 / 16 = 11 remainder 14 (E) 11 / 16 = 0 remainder 11 (B) read backwards: BEE -> 3054 = 0xBEE 255 / 16 = 15 remainder 15 (F), 15 / 16 = 0 remainder 15 (F) -> FF
Check it by converting back
Multiply each digit by a power of 16 and add: BEE = 11 * 256 + 14 * 16 + 14 = 2816 + 224 + 14 = 3054.
Code
JavaScript numbers lose precision above 2^53 - 1 (9007199254740991), so use BigInt for large values.
// JavaScript
(255).toString(16); // "ff"
parseInt("ff", 16); // 255
BigInt("18446744073709551615").toString(16); // "ffffffffffffffff"
# Python
hex(255) # "0xff"
int("ff", 16) # 255
// C#
255.ToString("X"); // "FF"
Convert.ToInt32("FF", 16); // 255Negative numbers and prefixes
Use the Decimal to Hex Converter for quick checks, or the Number Base Converter to see binary, octal, decimal and hex together.
- Hex has no sign of its own. Negative integers are shown in two's complement for a fixed width: -1 as a 32-bit value is FFFFFFFF.
- Code usually writes hex with a prefix: 0xFF in C, C#, Java and JavaScript, #FF in CSS colours.
- Pad to a fixed width when you need it, for example 0A rather than A for one byte.
Frequently asked questions
What is 255 in hex?
FF. It is 15 * 16 + 15, and it is the largest value of one byte.
Why do programmers use hex?
One hex digit is exactly four bits, so a byte is always two digits. That makes memory values, colours and hashes compact and easy to read.
How do I convert hex to decimal?
Multiply each digit by a power of 16 and add the results, or use parseInt(value, 16) in JavaScript.

