Decimal to Hex

Type a number and get its hexadecimal form, with the working written out two different ways.

Hexadecimal2AF
Binary10 1010 1111
Octal1257
Try

How it was worked out

Method 1: keep dividing by 16

Divide by 16 and write down the remainder. Keep dividing the quotient by 16 until you reach 0. Turn any remainder above 9 into a letter, then read the digits from the bottom up. Here it is for 687.

Divide by 16QuotientRemainderDigit
6874215F
42210A
2022

From the bottom up, that spells 2AF.

Calculators show decimals and not remainders. To get the remainder, multiply the whole part by 16 and subtract: 687 ÷ 16 = 42.9375, and 687 − 42 × 16 = 15.

Method 2: go through binary

If you're already comfortable with binary, you can take the scenic route. Convert to binary, split the bits into fours from the right, and swap each group for one digit.

687 = 10 1010 1111 = 2 A F

It's longer for big numbers, but it's a good way to check your division, since the two answers have to agree.

The quick way for numbers under 256

Anything up to 255 fits in two hex digits. Divide by 16 and the whole part gives the first digit, and the remainder gives the second. Take 200: sixteens go into it 12 times with 8 left over. 12 is C, so 200 is C8.

Learn the sixteen digits below and you'll be able to do most of these in your head.

DecimalHex
00
11
22
33
44
55
66
77
DecimalHex
88
99
10A
11B
12C
13D
14E
15F

Turning RGB into a colour code

This is probably the most common reason to convert by hand. A colour code is three bytes written side by side, so convert red, green and blue separately and always write two digits for each.

ChannelDecimalHex
Red255FF
Green13688
Blue000

That makes rgb(255, 136, 0) into #FF8800. Notice that 0 has to be written as 00, or the code won't work.

Common values

Select a number to see its working above.

DecimalHex
10A
15F
1610
1711
2014
3220
5032
6440
10064
1277F
12880
200C8
255FF
256100
5001F4
1,0003E8
1,024400
4,0961000
65,535FFFF

Negative numbers

On paper, −42 in hex is just −2A, and that's what this converter shows. Computers usually store negatives in two's complement, so the same number looks very different in a memory dump or a debugger.

In 8 bits, −42 is 11010110, which is D6

The binary converter shows the two's complement pattern at 8, 16, 32 and 64 bits.

Where answers usually go wrong

Writing a remainder as two digits

A remainder of 12 has to become C. If you write "12", then 200 turns into 128, which looks plausible and is wrong.

Reading the digits from the top down

The first remainder is the last digit. Read 687's digits in the wrong order and you get FA2, which is 4,002.

Using the decimal part of a calculator's answer

687 ÷ 16 shows 42.9375. The .9375 isn't your remainder. Multiply it by 16 to get 15, or use the subtraction above.

Dropping zeros from a colour code

rgb(10, 0, 5) is #0A0005. Each channel needs two digits, even if the first is 0.

Try these yourself

Work each one out on paper before you open it.

What is 200 in hex?

C8. 200 ÷ 16 is 12 with 8 left over, and 12 is C.

What is 1000 in hex?

3E8. The remainders are 8, then 14, which is E, then 3.

What is rgb(0, 128, 255) as a colour code?

#0080FF. 0 is 00, 128 is 80 and 255 is FF.

Common questions

What is 255 in hex?

It's FF, the largest number one byte can hold.

What is 16 in hex?

It's 10, meaning one sixteen and no units. Hex 10 and decimal 10 are different numbers.

Should hex be upper or lower case?

Either works. Colour codes and programs accept both, so it's a matter of style. This tool uses capitals because they're easier to tell apart from digits.

Do I need to add 0x?

Only if you're pasting it into code, where it tells the language the number is hex. Colour codes use # instead, and elsewhere you often need neither.

How large a number can I enter?

Up to 16,384 bits, which is about 4,900 decimal digits, with no rounding. The working is shown for values up to 64 bits.

Is my number sent anywhere?

No. The conversion runs in your browser, so it never reaches our server. A link you copy from the address bar can contain the number.