Decimal to Hex Converter

Decimal to Hex Converter. Type your number into Decimal Input and the Decimal to Hex Converter instantly returns its Hex Output. Use the hex shift calculator to perform a bitwise shift on a hex number without working out the binary by hand.

Need the base-16 form of a number right now? This decimal to hex converter takes any whole number you type, splits it into powers of 16 and returns the hexadecimal equivalent in one click — type 28,731 and you get 703B. Below you'll see how the math works, a full worked example with every remainder shown, and the values programmers reach for most often.

How the Decimal to Hex Converter Works

You enter a decimal number, press convert, and the decimal to hex converter tool runs the same repeated division you would do on paper: it divides the integer by 16, keeps the remainder, feeds the quotient back in, and stops when the quotient reaches zero. Writing the remainders in reverse order gives the finished hex string, so the whole decimal to hex conversion takes a handful of steps even for a large integer.

Base 10 Versus Base 16: Two Numeral Systems

The decimal system is the everyday decimal numeral system. Its radix is 10, it uses ten symbols (0 through 9), and every position is worth a power of 10. The hexadecimal system has a radix of 16, so it needs sixteen symbols and borrows the letters A to F for the values 10 to 15. In base 10 each position is worth ten times the one to its right; in base 16 each position is worth sixteen times the one to its right. That is why a short run of hex characters can stand in for a long decimal figure.

What Each Hex Digit Stands For

Every hex digit maps to exactly four binary digits, which is why one byte always fits in two hex characters, from 00 up to FF. Digits 0 to 9 look the same in both systems; only the six letters need a lookup:

What Each Hex Digit Stands For
Decimal remainderHex digitBinary
10A1010
11B1011
12C1100
13D1101
14E1110
15F1111

Decimal to Hexadecimal Conversion Step by Step

The conversion steps are identical for every number, whether you work them by hand or let a decimal to hexadecimal converter do it:

  1. Divide the number by 16 and note both the quotient and the remainder.
  2. Replace any remainder from 10 to 15 with its letter, A through F.
  3. Divide the new quotient by 16 and repeat until the quotient is 0.
  4. Write the remainders in reverse order to finish the decimal to hex conversion.

The one move that never changes is to divide by 16. A result such as 1F5 has only three characters because the quotient reached zero after three passes, and the number of passes always tells you the length of the hex string before you read a single remainder. Here is a full example to see that rhythm in action.

Long Division Method With Remainders

Take the decimal number 28,731. Each row of the table divides the previous quotient by 16 and records what is left over:

Long Division Method With Remainders
DivisionQuotientRemainder (decimal)Remainder (hex)Digit position
28,731 ÷ 161,79511B0
1,795 ÷ 16112331
112 ÷ 167002
7 ÷ 160773

Reading the hex column from the bottom up gives 703B. The final remainder, 7, is the most significant digit, while the first remainder, B, is the least significant digit. In symbols, each pass applies:

$$N = 16 \times q + r$$

where \(q\) is the quotient and \(r\) is the remainder, always between 0 and 15.

Ladder showing 28,731 divided by 16 four times, with remainders B, 3, 0 and 7 read in reverse to give the hex value 703B
The four divisions behind 28,731 = 703B.

Lookup Table Method for Small Values

When the number is below 16, skip the division entirely: the lookup table method maps it straight to a single hex character, so 12 becomes C and 15 becomes F. It also speeds up the longer method, because you read each remainder off the table of letters above instead of working it out again.

Checking the Result: Hex to Decimal

To verify an answer, run it backwards as a hex to decimal check. Multiply each digit by its power of 16 and add the results:

$$703B_{16} = 7 \times 16^{3} + 0 \times 16^{2} + 3 \times 16^{1} + 11 \times 16^{0} = 28{,}672 + 0 + 48 + 11 = 28{,}731$$

Because the total matches the number you started with, the conversion is right.

Waterfall chart of the hex digits of 703B contributing 28,672, 0, 48 and 11 to reach the decimal total 28,731
Each hex digit's place value adds up to the original decimal number.

Turning a Decimal Crash Code Into Its Hex Equivalent

A support engineer exports a customer's application log and finds the line exit code 3221225477. The log viewer prints exit codes in decimal, but the vendor's troubleshooting pages list them in hex, so nothing in the search results matches yet. The only way to compare them is a quick decimal to hex conversion.

She types 3221225477 into the converter and presses convert. The tool divides by 16 eight times, as the table below shows, and the first seven remainders come out as 5, 0, 0, 0, 0, 0 and 0, with the last quotient, 12, becoming the letter C.

Turning a Decimal Crash Code Into Its Hex Equivalent
StepQuotientRemainder (hex)
1201,326,5925
2 to 712,582,912 down to 120 each time
80C

Read from the bottom up, the result is C0000005. Prefixed the way the vendor writes it, that is 0xC0000005, which Microsoft documents as STATUS_ACCESS_VIOLATION: the process touched memory it had no right to read or write.

That single match changes what she does next. Instead of reinstalling the whole application, she asks the customer to send the module list from the crash report, because an access violation points at one faulty library rather than a corrupt install. She also reruns the converter on the second code in the log, 3221226356, and gets C0000374, the code for heap corruption, so it is a different failure and the two tickets stay separate.

Decimal to Hex Conversion Table for Common Values

A short conversion table of boundary values helps you sanity-check any result at a glance. Each row marks the point where a hex string needs one more character:

Decimal to Hex Conversion Table for Common Values
DecimalHexWhat it marks
15FLargest single hex digit
255FFLargest unsigned byte
256100First value that needs three characters
4,095FFFLargest twelve-bit value
65,535FFFFLargest sixteen-bit value

If your answer has more characters than the row for your magnitude allows, one of the remainders went wrong somewhere.

Decimal to Binary and Hex: Why Programmers Use Both

Inside a computer, everything is stored as binary numbers, and long strings of ones and zeros are hard to read. Hex is the compact shorthand: 28,731 is 111000000111011 in binary but just 703B in hex, and grouping the binary into fours (0111 0000 0011 1011) shows each hex digit lining up with its own group. That is why decimal to binary and decimal-to-hex work are usually learned together in computing and mathematics courses. Any number system with a power-of-two base converts to binary this cleanly, but base 16 is the one programmers settled on because two hex characters describe a full byte.

Where a Hex Equivalent Shows Up in Programming

Almost every developer meets hexadecimal sooner or later, because it is the human-readable face of binary data.

Reading a Hex Value in Color Codes

In web development, color codes in HTML and CSS pack three bytes into one hex value, one byte each for red, green and blue. Each channel is a decimal number from 0 to 255 that you turn into two hex characters with the same divide-by-16 method. A teal that uses red 18, green 160 and blue 110 converts one channel at a time:

Reading a Hex Value in Color Codes
ChannelDecimalHex
Red1812
Green160A0
Blue1106E

Joined together, those channels give #12A06E, and the same method works for every one of the 16.7 million colors a screen can show, since each channel is just one of 256 numbers between 0 and 255.

Memory Addresses and Error Codes

Debuggers print memory addresses in hex because a 64-bit address would be unreadable as a decimal integer, and tracing what sits at a given memory location is a daily task in low-level debugging. Hex also dominates error codes and network settings, so IT professionals convert a decimal value from a log into hex to match it against vendor documentation.

Decimal to Hex in Python

Most languages have a built-in for this. In Python, hex() returns the value with its prefix and format() lets you choose the case:

n = 28731
print(hex(n))            # 0x703b
print(format(n, "X"))    # 703B
print(format(n, "04X"))  # 703B, padded to four characters

Free Online Decimal to Hexadecimal Calculator Tips

Whichever free online decimal to hexadecimal calculator you choose, three formatting choices matter once you paste the result into code:

  • Prefix: the 0x prefix marks a number as hex in most programming languages, while CSS color codes use a leading # instead.
  • Case: uppercase is common in documentation and colors, lowercase is common in source code, and the value is identical either way.
  • Width: padding with leading zeros lets you pad a result to a fixed-width byte boundary, so 5 is written as 05 and values line up in a dump you later copy elsewhere.

A hex calculator that adds and subtracts in base 16 is a separate tool; here the job is only to convert, so you can check the answer yourself with the long division steps above.

Practice Problems

Work these three by hand, then check them against the converter:

  • Convert 3,917 to hex. The answer is F4D.
  • Convert 48,879 to hex. The answer is BEEF.
  • Convert 1,000,000 to hex. The answer is F4240.

For a quick pattern check, notice that every answer's length matches the boundary table: 3,917 sits between 256 and 4,095, so it needs three characters, and 1,000,000 needs five.

Decimal to Hexadecimal Length for Larger Numbers

Hex earns its place with big numbers. Every extra hex character multiplies the range by 16, while every extra decimal figure only multiplies it by 10, so large numbers shrink faster in hex than small ones. Each decimal value below sits at the top of its hex length, which makes it a handy example of the saving:

Dumbbell chart comparing the characters needed in decimal and hex for 255, 4,095, 65,535, 1,000,000 and 4,294,967,295
Hex always needs fewer characters than decimal for the same large number.

The gap widens as the numbers grow, and that is the real reason developers writing 32-bit masks or checksums choose hex: FFFFFFFF is eight characters, where the same numbers written in decimal run to ten.

Common Mistakes When You Convert Decimal to Hex

Most wrong answers come from three slips. First, reading the remainders from the top down instead of in reverse order, which flips the number around. Second, writing a remainder of 10 to 15 as two digits instead of a single letter. Third, stopping one division early, before the quotient reaches zero, which drops the leading digit. If you want to convert decimal to hex reliably, write each quotient and remainder on its own row, the way the table above does, and cross-check with the hex to decimal expansion before you copy the answer anywhere.

Two inputs also deserve a warning before you start. Fractions such as 0.5 are not covered by the whole-number method above, because their digits come from repeated multiplication rather than division. Negative values depend on the storage format in use: the same bit pattern can mean a large positive count or a small negative one, so a signed result must be read against the width of the field it came from. Stick to non-negative whole values when you want a plain, predictable answer.