DecimalHex

Whole numbers of any size, negatives too

Try
Hex
3E8
Binary 11 1110 1000 · Octal 1750

Division by 16

The remainders are the hex digits
DivideQuotientRemainderHex digit
1000 ÷ 166288
62 ÷ 16314E
3 ÷ 16033

Remainders, bottom to top: 3E8.

Signed and unsigned

The value in 8, 16, 32 and 64-bit registers
WidthHex patternUnsignedSigned
8-bit—Too large for 8 bits
16-bit03E810001000
32-bit0000 03E810001000
64-bit0000 0000 0000 03E810001000
Guide

How to convert decimal to hex

  1. Divide the number by 16 and write down the remainder, a value from 0 to 15.
  2. Divide the quotient by 16 again, and keep going until the quotient is 0.
  3. Write the remainders as hex digits (10 to 15 become A to F) from the last one to the first. 1000 leaves 8, 14 and 3, so it's 3E8.

Worked example

Converting 1000 to hex by dividing by 16:

DivideQuotientRemainder
1000 ÷ 16628 = 8
62 ÷ 16314 = E
3 ÷ 1603 = 3

Remainders, bottom to top → 3E8

  • Negative numbers get a minus sign, like -2A. The table under the converter shows the two's complement form computers store.
  • Every hex digit is exactly 4 bits, so you can also convert through binary and group the bits in fours.
  • Going the other way? Use the hex to decimal converter.

Hex digits in binary

4 bits per digit
HexBinaryDecimal
000000
100011
200102
300113
HexBinaryDecimal
401004
501015
601106
701117
HexBinaryDecimal
810008
910019
A101010
B101111
HexBinaryDecimal
C110012
D110113
E111014
F111115
Learn

Decimal to hex conversion explained

Three ways to convert by hand, negative numbers, and the values you'll use most.

Colors, memory addresses and byte values are usually written in hexadecimal, and a decimal to hex converter turns an ordinary base-10 number into that base-16 form. Type a number above to get its hex value, with every division by 16 shown and the two's complement patterns for negative numbers. Below are three ways to convert decimal to hex by hand, and the values you'll meet most often.

Method 1: divide by 16

The standard method is repeated division. Divide your number by 16, write down the remainder, then divide the quotient by 16 again. Stop when the quotient reaches 0. The remainders are the hex digits, read from the last one back to the first, with 10 to 15 written as A to F. For 1,000: 1,000 ÷ 16 = 62 remainder 8, 62 ÷ 16 = 3 remainder 14, and 3 ÷ 16 = 0 remainder 3. Reading upward gives 3, 14 and 8, so 1,000 is 3E8. Larger numbers just take more steps. 48,879 leaves 15, 14, 14 and 11, which spells BEEF.

Method 2: subtract powers of 16

If you know the powers of 16 (1, 16, 256, 4,096, 65,536), you can build the hex number from the left instead. Find the largest power that fits, see how many times it fits, and carry the rest down. For 1,000, 256 fits 3 times (768), leaving 232. Then 16 fits 14 times (224), so the next digit is E, leaving 8 for the ones place. The result is again 3E8. This method is handy for checking an answer, because each digit's value is easy to see.

Method 3: go through binary

Every hex digit is exactly four bits, so if you already have the binary, converting to hex is quick. 1,000 in binary is 1111101000. Split it into groups of four from the right, 11 1110 1000, and replace each group with its hex digit: 3, E and 8. The decimal to binary converter gives the bits, and the binary to hex converter does the grouping.

Common decimal values in hex

DecimalHex
10A
15F
1610
10064
255FF
256100
1,0003E8
4,0961000
65,535FFFF
1,000,000F4240

Notice that 16, 256 and 4,096 are written 10, 100 and 1000 in hex, just as 10, 100 and 1,000 are round numbers in decimal.

Checking your answer

It's easy to check a conversion by going back the other way. Multiply each hex digit by its power of 16 and add them up: 3E8 is 3 × 256 + 14 × 16 + 8 × 1, which is 768 + 224 + 8 = 1,000. You can also predict how many digits the answer needs. Each extra hex digit multiplies the range by 16, so n digits hold every number up to 16ⁿ − 1. Two digits go up to 255, three up to 4,095 and four up to 65,535. Since 1,000 is between 256 and 4,095, it needs three hex digits. The hex to decimal converter shows that working for any value.

Negative numbers in hex

Mathematically, a negative number in hex simply keeps its minus sign: −42 is -2A. Computers store negative integers in two's complement instead, in a fixed number of bits. −42 is D6 in 8 bits, FFD6 in 16 bits and FFFFFFD6 in 32 bits, and −1 is all F's at every width. To find the pattern, add 2 to the power of the width: −42 + 256 = 214, which is D6. The Signed and unsigned table under the converter shows all four widths, and the two's complement calculator walks through the encoding.

Where you'll convert decimal to hex

  • Colors. CSS color values are three bytes in hex. Red 255, green 128 and blue 0 become #FF8000. The RGB to hex converter does this for whole colors.
  • Unicode and HTML. Code points are written in hex, so character 233 is U+00E9, and HTML accepts é for é.
  • Programming. Bit masks, flags and memory sizes are clearer in hex: 65,535 is 0xFFFF, and 4,096 is 0x1000.

Getting the format you need

  • Turn on Add 0x prefix for a value you can paste straight into code, and switch off Uppercase for lowercase letters.
  • Numbers of any size convert exactly, so values beyond 2⁵³ won't be rounded the way they are in many calculators.
  • For decimal to binary, octal and hex together, use the hex converter.

Checking an answer takes seconds the other way round: the hex to decimal converter multiplies each digit back out by its power of 16.

FAQ

Frequently asked questions

Quick answers about the decimal to hex converter and how it works.

How do I convert decimal to hex?

Divide the number by 16 and note the remainder, then keep dividing the quotient until it reaches 0. The remainders, read from last to first and with 10 to 15 written as A to F, are the hex digits. 1,000 leaves 8, 14 and 3, so it's 3E8.

What is 255 in hex?

255 is FF, because 15 × 16 + 15 = 255. One more, 256, is 100 in hex, just as 99 + 1 rolls over to 100 in decimal.

How do I convert a negative number to hex?

Convert the positive value and add a minus sign: −42 is -2A. Computers store negative numbers in two's complement instead, so −42 is D6 in 8 bits and FFFFFFD6 in 32 bits. The converter shows all of these.

Why are the remainders read from bottom to top?

The first division by 16 gives the remainder for the ones place, the next gives the 16s place, then the 256s, and so on. Since the ones digit is written last, you read the remainders in reverse order.

How many hex digits does a number need?

Each hex digit holds 4 bits, so two digits cover one byte. Numbers up to 255 fit in two hex digits, up to 65,535 in four, and up to 4,294,967,295 in eight.

How do I convert decimal to hex in code?

In JavaScript, (255).toString(16) gives ff. In Python, hex(255) gives 0xff, and format(255, "X") gives FF. This converter gives the same digits, uppercase or lowercase, with an optional 0x prefix.

Still have a question?Contact us