How to use the Decimal to Hexadecimal tool
- Type the decimal number into the Base-10 number box, for example 45.
- Select Convert, or select Example to load 45 and run it.
- Read the hexadecimal value in the Result box. It is uppercase and has no 0x prefix.
- Select Copy to copy the hex digits, then add 0x or # in your own code if the syntax needs it.
How decimal to hex conversion works
Hexadecimal is base 16. It uses the digits 0 to 9 and then A, B, C, D, E and F for the values 10 to 15. To convert by hand, divide the number by 16 repeatedly and record each remainder as one hex digit. Read the remainders from last to first.
One hex digit covers exactly four bits, so a byte is always two hex digits. That is the reason memory dumps, color codes and hashes are written in hex and not in decimal.
45 / 16 = 2 remainder 13 -> D
2 / 16 = 0 remainder 2 -> 2
45 = 2D (2 x 16 + 13)Decimal to hex reference values
The tool does not pad its output. 10 gives A, not 0A. When you are writing bytes, colors or fixed-width registers, add the leading zero yourself.
An RGB color takes three conversions, one per channel. Orange, rgb(255, 165, 0), becomes FF, A5 and 0, written #FFA500 once the last channel is padded to 00.
10 -> A
255 -> FF
1000 -> 3E8
65535 -> FFFF
1000000 -> F4240
4294967295 -> FFFFFFFFNegative numbers and signed error codes
A minus sign is accepted and carried through: -255 converts to -FF. The tool does not produce two's complement. That matters for values such as Windows HRESULT codes, which are often logged as signed 32-bit decimals. -2147467259 converts here to -7FFFBFFB. To get the familiar 80004005, add 4294967296 (2^32) to the negative value first, which gives 2147500037, and convert that.
Accepted input and number size
Enter one whole number using the digits 0 to 9, with an optional leading minus sign. Surrounding whitespace is removed. The converter rejects decimal points, commas, a plus sign and exponent notation, naming the first invalid character in its error message. Input longer than 4,096 characters is refused as well.
Numbers are handled as arbitrary-precision integers, so 18446744073709551615 converts to FFFFFFFFFFFFFFFF with no loss.
Frequently asked questions
What is 45 in hexadecimal?
45 in hex is 2D. Two sixteens make 32 and the remaining 13 is written D. In source code it is usually written 0x2D.
What is 255 in hex?
255 is FF, the largest value of one byte. 256 is 100 in hex, because it needs a third digit.
Is the output uppercase or lowercase?
The converter prints uppercase letters, such as 1ED for 493. Hexadecimal is not case-sensitive, so 1ed means the same value. Lowercase it in your editor if your style guide prefers that.
Does the result include the 0x prefix?
No. The output is the bare digits. Prefixes are language syntax: 0x in C, JavaScript and Python, a number sign in CSS colors, and a trailing h in some assemblers. Add whichever your target needs.
Can I convert several decimal numbers at once?
No. The box takes one number per conversion, and a space or comma between numbers is reported as an invalid digit. Convert each value separately.
How do I convert a negative decimal to two's complement hex?
Add 2 to the power of the word size to the negative number, then convert the sum. For 8 bits add 256, so -128 becomes 128 and converts to 80. For 32 bits add 4294967296.