Skip to content

Decimal to Hex Converter - Number to Hexadecimal

Hexadecimal (16)
—
Other bases
Binary (2)—
Octal (8)—
Decimal (10)—
Base 36—

Convert Decimal Numbers to Hex

Type a whole number and the hexadecimal result appears immediately in upper case, along with binary and octal. Turn on grouping to split long hex strings into blocks of four digits (two bytes). Values beyond 253, where most calculators start rounding, convert exactly.

The Divide-by-16 Method

Divide the number by 16, keep the remainder as one hex digit, and repeat with the quotient until it reaches zero. Remainders of 10 to 15 are written A to F. The first remainder you get is the rightmost digit.

Worked example: 48879

Number÷ 16RemainderHex digit
48879305415F
305419014E
1901114E
11011B

Reading the digits from the bottom up gives BEEF, so 48879 = 0xBEEF. Check: 11 × 4096 + 14 × 256 + 14 × 16 + 15 = 48879.

If you already know the binary form, there is a shortcut: split the bits into groups of four from the right and replace each group with one hex digit.

Powers of 16

PowerDecimalHex
16011
1611610
162256100
1634,0961000
16465,53610000
1651,048,576100000
16616,777,2161000000
167268,435,45610000000
1684,294,967,296100000000

Common Decimal to Hex Conversions

DecimalHex
10A
15F
1610
3220
6440
10064
1277F
12880
200C8
255FF
256100
5001F4
1,0003E8
1,024400
4,0961000
10,0002710
65,535FFFF
1,000,000F4240
16,777,215FFFFFF

Example: RGB to a Hex Colour

Web colours are three bytes written as hex: red, green and blue. To turn rgb(70, 130, 180) into a hex code, convert each value on its own and pad to two digits:

  • 70 ÷ 16 = 4 r 6, so red is 46.
  • 130 ÷ 16 = 8 r 2, so green is 82.
  • 180 ÷ 16 = 11 (B) r 4, so blue is B4.

Joined together that is #4682B4, the CSS colour "steelblue". Values below 16 need a leading zero: 9 becomes 09, not 9.

Typical Uses

Decimal to hex comes up when writing colour codes from RGB values, setting register or flag values in firmware, building byte sequences for protocols, and reading Unicode code points. For the reverse direction, use hex to decimal; to convert between other bases, use the number base converter.

Related Tools

Frequently Asked Questions

How do you convert decimal to hexadecimal?
Divide the number by 16 and note the remainder, writing 10 to 15 as A to F. Divide the quotient by 16 again and repeat until the quotient is 0. Read the remainders from last to first. For 300: 300 / 16 = 18 r 12 (C), 18 / 16 = 1 r 2, 1 / 16 = 0 r 1, so 300 is 12C.
How do I convert RGB values to a hex colour code?
Convert each channel (0 to 255) to two hex digits and join them. rgb(255, 165, 0) becomes FF, A5 and 00, so the colour is #FFA500. Pad single digits with a leading zero, for example 9 becomes 09.
Should I add 0x in front of the result?
It depends on where you use it. C, Java, JavaScript, Python and most other languages expect a 0x prefix for hex literals (0x12C). CSS colours use # instead, and many tools and documents just write the digits. The converter shows the digits alone so you can add whichever prefix you need.
How do I convert a negative number to hex?
The converter shows a minus sign (-FF). For a two's complement value of a fixed width, add 2^width first: for 32 bits, -1 + 4294967296 = 4294967295 = FFFFFFFF.