Decimal to Hex Converter
Result
Hexadecimal
- Place values
- 2×4096 + 10×256 + 3×16 + 15
A decimal to hex converter rewrites a whole number from base ten into base sixteen. The method is the same repeated division that produces binary, with sixteen in place of two: divide the number by sixteen, keep the remainder, divide the quotient by sixteen, and carry on until the quotient reaches zero. What changes is the alphabet. Dividing by two can only leave 0 or 1, but dividing by sixteen can leave any value from 0 to 15, and base sixteen writes those ten-to-fifteen values as the letters A to F — A for 10, B for 11, up to F for 15. So the remainders do not come out as hexadecimal digits directly; they come out as numbers, and every remainder above 9 has to be written as its letter before the answer is finished. Take 10815: 10815 ÷ 16 is 675 remainder 15, then 675 ÷ 16 is 42 remainder 3, then 42 ÷ 16 is 2 remainder 10, and finally 2 ÷ 16 is 0 remainder 2. Read bottom up, the remainders are 2, 10, 3, 15 — which become 2, A, 3, F, so 10815 is 2A3F in hexadecimal. The letters are the whole point of the page. The place value sum printed beside the answer shows the same number from the other end: in base sixteen the positions are worth 4096, 256, 16 and 1, and 2A3F is 2×4096 plus 10×256 plus 3×16 plus 15, which adds back to 10815. Base sixteen is used because one hexadecimal digit is exactly four binary digits, so a byte is always two characters and a thirty-two bit value is always eight — which is why colour codes, memory addresses and hashes are written this way.
Dividing 10815 by sixteen, one round at a time, until the quotient reaches zero
| Round | Division | Quotient | Remainder |
|---|---|---|---|
| 1 | 10815 ÷ 16 | 675 | 15 (F) |
| 2 | 675 ÷ 16 | 42 | 3 |
| 3 | 42 ÷ 16 | 2 | 10 (A) |
| 4 | 2 ÷ 16 | 0 | 2 |
Two of the four remainders in this ladder are written as a number followed by its letter in brackets — 15 (F) and 10 (A) — and that doubled form is the reason the table exists. The arithmetic gives you 15; the answer needs F. Anyone who divides correctly and then copies the remainder column down as it stands writes 2103 instead of 2A3F, which is the one mistake this conversion invites. Read the column from the bottom up and the characters of the answer appear in order: 2, 10, 3, 15, which is 2A3F once the two values above nine are replaced. The table is fixed at 10815 while the panel above converts whatever you typed, because it is showing the method rather than a result. The quotient falls by a factor of about sixteen each round, so a ladder for even the largest allowed input is only fourteen rows long — which is exactly the length of the hexadecimal ceiling, 1FFFFFFFFFFFFF.
Formula
10815 ÷ 16 = 675 r 15 → 675 ÷ 16 = 42 r 3 → 42 ÷ 16 = 2 r 10 → 2 ÷ 16 = 0 r 2 ⇒ 10815 = 2A3F = 2×4096 + 10×256 + 3×16 + 15
- 10815
- The whole number to convert, written in base ten. A decimal point or a thousands separator is refused rather than rounded away, so write 10815 rather than 10,815
- ÷ 16
- The step that repeats, with sixteen in place of the two that the binary version of this page uses. Sixteen is the base you are converting into, so each round asks how many sixteens fit and what is left over
- quotient
- The part that carries to the next round. The process stops when the quotient reaches zero, which means no higher position in the answer is needed
- remainder
- The digit produced by that round, and here it can be anything from 0 to 15 rather than only 0 or 1. Erasing that difference is the most common way to get this conversion wrong: the remainder 15 is not the digit 15, because base sixteen has no single character for it
- A — F
- The letters that stand for the values ten to fifteen, with A as 10, B as 11, C as 12, D as 13, E as 14 and F as 15. They are not a separate notation to learn: each one is just the number that could not be written as a single decimal character
- ⇒ 2A3F
- The digits assembled from the bottom up, with every remainder above 9 already turned into its letter. The first remainder found is the rightmost character, so reading the rounds in the order they were written gives the answer reversed
- 2×4096 + 10×256 + 3×16 + 15
- The answer read back as place values. Unlike binary, the coefficients are not all ones — this is the check that catches a letter converted to the wrong number, because a wrong A would change the sum
Hexadecimal is the shorthand engineers read, so this conversion comes up whenever a value has to move between the two. Colour codes are the everyday case: a channel running from 0 to 255 is two hexadecimal characters, which is why a colour is written as six of them and why a designer's 10815 and a developer's 2A3F are the same colour. Memory addresses, checksums, hashes and the register values in a datasheet are all printed in base sixteen for the same reason — four bits per character, so the width of a value is legible at a glance. Anyone reading a stack trace or a packet dump is doing this conversion in the other direction dozens of times an hour, and anyone writing a mask or a magic number is doing it in this one. Coursework asks for it directly, usually as convert decimal to hex and show the working, which is what the ladder below is: one line per division, with the letters already substituted. It is also the step that makes a value's width obvious, because two characters is a byte and eight is a thirty-two bit word, so the conversion answers how many characters a value will occupy in the format it is going into.
Worked examples
Writing 10815 in hexadecimal
- 10815 ÷ 16 = 675, remainder 15 — write down 15, which is F
- 675 ÷ 16 = 42, remainder 3
- 42 ÷ 16 = 2, remainder 10 — which is A
- 2 ÷ 16 = 0, remainder 2 — the quotient has reached zero, so stop
- Read the remainders from the bottom up: 2, 10, 3, 15
- Replace 10 with A and 15 with F: the answer is 2A3F
The default, and the example that shows both substitutions. Note that two of the four remainders need a letter, which is typical rather than unlucky: a remainder above 9 turns up about six times in sixteen, and an answer three or four characters long will usually contain at least one.
A full byte, 255
- 255 ÷ 16 = 15, remainder 15 — write it as F
- 15 ÷ 16 = 0, remainder 15 — write it as F
- The quotient has reached zero, so read the two remainders bottom up: FF
Two characters for the largest value a single byte can hold, which is exactly why hexadecimal exists. The pair FF and 255 is worth memorising: it is the ceiling for a colour channel, an unsigned byte in most languages, and one character's worth of raw data.
A power of sixteen, 1048576
- 1048576 ÷ 16 = 65536, remainder 0
- 65536 ÷ 16 = 4096, remainder 0
- 4096 ÷ 16 = 256, remainder 0
- 256 ÷ 16 = 16, remainder 0
- 16 ÷ 16 = 1, remainder 0
- 1 ÷ 16 = 0, remainder 1 — read bottom up to get 100000
The hexadecimal echo of the power-of-two example on the binary page: a power of the base comes out as a single 1 followed by zeros. 1048576 is 16⁵ and also 2²⁰, which is the point of the notation — the same value is 100000000000000000000 in binary and 100000 in hexadecimal, and the second is readable.
A negative number
- The minus sign is carried, not converted: the digits are worked out for 10815 as in the first example
- 10815 ÷ 16 = 675 remainder 15, and so on down to 0 remainder 2
- The digits read bottom up are 2, A, 3, F
- The sign goes on the front: -2A3F
A leading minus sign is accepted and printed in front, and the place value sum is wrapped in brackets so the minus applies to the whole sum rather than to its first term. Note what this is not: it is a signed reading of a magnitude, not the two's complement bit pattern a machine would store. If you need the register contents of a negative value rather than its signed notation, that is a different question and a different page.
Limitations
This page converts whole numbers only, so a decimal point is refused rather than rounded — 10815.5 cannot be converted here. Thousands separators are refused too: write 10815 rather than 10,815, because a comma is a decimal point in some languages and guessing between the two readings is worse than asking for it plainly. The input may be at most 9007199254740991, which is fourteen hexadecimal characters, and its hexadecimal form is 1FFFFFFFFFFFFF — the same ceiling that appears on the binary pages as fifty-three digits, because it is one limit written in two bases. Leading zeros and a leading minus sign are both accepted; the minus produces a signed reading of the magnitude, not a two's complement bit pattern. The table below prints the ladder for 10815 and does not follow the number you typed. Converting in the other direction, from hexadecimal back to decimal, is a separate page, and this one does no arithmetic on the result.
Frequently asked questions
- How do I convert a decimal number to hex by hand?
- Divide by sixteen, write down the remainder, then divide the quotient by sixteen and repeat until the quotient is zero. Read the remainders from the bottom up, and replace every remainder above 9 with its letter: 10 is A, 11 is B, 12 is C, 13 is D, 14 is E and 15 is F. For 10815 the remainders come out 15, 3, 10, 2 from top to bottom, which read upwards and substituted gives 2A3F.
- Why are letters used in hexadecimal at all?
- Because base sixteen needs sixteen single characters and the decimal digits only supply ten. The six extra symbols have to come from somewhere, and letters are the convention every system agrees on. A is ten and F is fifteen, so the digits of the system run 0 to 9 and then A to F. This is not an extra thing to memorise on top of the conversion — a letter is only ever the name of a remainder that did not fit in a single decimal character.
- What is the largest decimal number I can convert here?
- 9007199254740991, which is 1FFFFFFFFFFFFF in hexadecimal — fourteen characters. The limit comes from the same place as the fifty-three digit limit on the binary pages, because it is the same number expressed in two bases. Anything larger is refused with a message rather than converted, since past that width a machine cannot hold neighbouring whole numbers apart and a converted answer could not be trusted.
- Is hexadecimal the same as binary, just shorter?
- It is the same value written in a base that is a power of two, which is why the two are so easy to move between. Each hexadecimal character is exactly four binary digits, so 2A3F is 0010 1010 0011 1111 with nothing left over. That is not a coincidence of this example: it holds for every hexadecimal number, and it is the reason hexadecimal is used. Nothing is lost in the change and nothing has to be rounded.
- Can I convert a decimal number with a fractional part?
- Not here. This page takes whole numbers, so 10815.5 is refused rather than rounded. Fractions in base sixteen are well defined — the positions to the right of the point are worth a sixteenth, a two-hundred-and-fifty-sixth, and so on — but accepting them would mean deciding how many characters to keep and how to round the last one, and every page in this group converts whole numbers.
- Why does the page print a place value sum as well as the hexadecimal number?
- Because it is the check that catches the substitution mistake. If you turned the remainder 15 into the wrong letter, or used A where you needed F, the printed sum will not add back up to the number you started with — 2×4096 + 10×256 + 3×16 + 15 is 10815 only when the letters have been read correctly. Unlike the binary version of this sum, the coefficients are not all ones, so every character of the answer is separately accounted for.
References
- Hexadecimal — base sixteen, the letters A to F as the values ten to fifteen, and conversion to and from decimal — Wolfram MathWorld (United States)
- Number base — why a numeral's value depends on its position and on the base, and how one quantity is written in several bases — Wolfram MathWorld (United States)
- Powers of two — the sequence that the base-sixteen positions double up into, catalogued as OEIS A000079 — OEIS Foundation Inc. (United States)
- 教育部关于印发义务教育课程方案和课程标准(2022 年版)的通知——The fifth item in the annex list of this notice is the Mathematics Curriculum Standards for Compulsory Education (2022 edition); positional systems and conversion between different bases are part of the Number and Algebra strand of these standards, and the wording of the standards and the grade-band breakdown are governed by that annex — 中华人民共和国教育部