Hex to Decimal Converter
Result
Decimal
- Place values
- 2×4096 + 10×256 + 3×16 + 15
A hex to decimal converter rewrites a hexadecimal number in base ten, and unlike the conversion to binary it is real arithmetic. The value of a hexadecimal number is the sum of each character multiplied by the power of sixteen that its position is worth, counting from zero at the right. 2A3F has an F in the last place, so the F is worth 15; a 3 in the next place, worth 3×16; an A in the one after that, worth 10×256; and a 2 at the front, worth 2×4096. Adding them gives 10815. The letters are where this goes wrong, and they go wrong in two ways. First, A has to become 10 and F has to become 15 before anything is multiplied — reading A as 1 gives an answer that looks plausible and is wrong. Second, the value a letter stands for is multiplied by its position, so an F in the last place is 15 and an F one place to the left is 240; the letter is not the amount, it is a coefficient. The powers of sixteen are the other half of the page, and they have a shape worth knowing: 1, 16, 256, 4096, 65536, all the way up, each one sixteen times the last. Reading a hexadecimal number off against that list, right to left, is faster than computing any of the powers on the spot. Because sixteen is a power of two, these are also the powers of two taken four at a time — 16 is 2⁴, 256 is 2⁸, 65536 is 2¹⁶ — which is why the same positions that hold four bits each carry one power of sixteen each. The page prints the whole sum beside the answer, so the result can be checked term by term: 2×4096 + 10×256 + 3×16 + 15 is 10815, and a mistake in any single character shows up as a sum that does not come back to the number you expected.
The powers of sixteen, from the rightmost position to the widest one an accepted input can reach
| Position | Power | Value |
|---|---|---|
| 13 | 16¹³ | 4503599627370496 |
| 12 | 16¹² | 281474976710656 |
| 11 | 16¹¹ | 17592186044416 |
| 10 | 16¹⁰ | 1099511627776 |
| 9 | 16⁹ | 68719476736 |
| 8 | 16⁸ | 4294967296 |
| 7 | 16⁷ | 268435456 |
| 6 | 16⁶ | 16777216 |
| 5 | 16⁵ | 1048576 |
| 4 | 16⁴ | 65536 |
| 3 | 16³ | 4096 |
| 2 | 16² | 256 |
| 1 | 16¹ | 16 |
| 0 | 16⁰ | 1 |
Fourteen rows, from 16⁰ up to 16¹³, and the length is not arbitrary: fourteen characters is the widest input this family accepts, so the table covers every position an answer can use and stops. Reading it downwards is reading the answer's positions from right to left — the last row is the rightmost character and the first row is the leftmost. The middle column is the position written as a power, which is what the sum in the panel above multiplies by; the third column is that power worked out, which is what you multiply by in practice. These values double up with the binary pages: 16 is 2⁴, 256 is 2⁸ and 65536 is 2¹⁶, because one hexadecimal character holds four bits. So the same table answers how much a four-bit group is worth when it is read as a number rather than as bits. It is fixed and does not follow what you typed.
Formula
2A3F = 2×16³ + 10×16² + 3×16¹ + 15×16⁰ = 2×4096 + 10×256 + 3×16 + 15 = 10815
- 2A3F
- The hexadecimal number to convert. Letters are case-insensitive, so 2a3f and 2A3F are the same value; a leading zero changes nothing, and a leading minus sign gives a negative result
- 16ⁿ
- The power of sixteen attached to a position, counted from zero at the rightmost character. The rightmost is worth 16⁰, which is 1, the next 16¹, which is 16, and each step left multiplies by sixteen again
- 2, 10, 3, 15
- The characters read as values, with the letters already replaced — A becomes 10 and F becomes 15 before any multiplication happens. Reading A as 1 is the mistake this line exists to prevent, and it is the most common way this conversion goes wrong
- 2×4096
- One term of the sum: the value of the character times the power of its position. Every character contributes a term, including the ones that are zero, though a zero term changes nothing and is simply left out of the printed sum
- = 10815
- The total of the terms. It is a decimal number rather than a string of digits in some other base, which is why this page's answer can be used in further arithmetic directly
- 14 characters
- The widest input accepted, which is 1FFFFFFFFFFFFF. Fourteen characters is the length at which the value reaches 9007199254740991, past which a machine cannot hold neighbouring whole numbers apart, so a longer input is refused rather than converted
Reading a hexadecimal value as a decimal one is what you do whenever a number written for a machine has to be compared against a number written for a person. A colour code has three channels of two characters each, and knowing that FF is 255 and 80 is 128 is the difference between adjusting a shade by eye and adjusting it by number. Sizes are the same story: 400 hexadecimal is 1024, which is a familiar page size, and a memory map printed as 0x100000 is 1048576 bytes to whoever has to add a second region to it. Anyone checking a checksum, comparing a hash prefix or converting the mask in a datasheet does this conversion, and anyone reading a serial number or an identifier that turned out to be hexadecimal does it too. Coursework asks for it as convert hex to decimal, usually with the powers written out, which is exactly the sum this page prints: one term per character, with the letters already substituted. It is also the conversion to reach for when a hexadecimal answer from another tool needs to be sanity-checked, since the decimal total is the one number against which all the others can be compared.
Worked examples
Reading 2A3F
- Write the powers of sixteen under the four characters, from the right: 1, 16, 256, 4096
- Replace the letters with their values: A is 10 and F is 15
- Multiply each: 2×4096 is 8192, 10×256 is 2560, 3×16 is 48, 15×1 is 15
- Add the four terms: 8192 + 2560 + 48 + 15 = 10815
The default, and the one where both letters need converting. The A is not a 1 and the F is not a 5 — reading the string as if the letters were digits would give an answer of about two thousand, which is far enough off to be obvious. The subtler mistake is a letter that has been converted correctly but multiplied by the wrong power.
A full byte, FF
- Two characters, so the positions are worth 16 and 1
- F is 15, so the left character contributes 15×16 = 240
- The right character contributes 15×1 = 15
- 240 + 15 = 255
Two characters and the largest value they can hold, which is why FF is 255 rather than 256: the range starts at 00. This pair is worth remembering outright, since it comes up in colour values, byte-sized fields and any hexadecimal string of exactly two characters.
Reading B2
- B is 11, so the left character contributes 11×16 = 176
- The right character contributes 2
- 176 + 2 = 178
B sits one above A, so 11×16 rather than 10×16 — the difference between reading B as 11 and reading it as 10 is sixteen, which is a whole hexadecimal place. This is the same value the binary pages use as an eight-bit example, and 10110010 is what it looks like in base two.
The largest input, 1FFFFFFFFFFFFF
- Fourteen characters, so the positions run from 16¹³ down to 16⁰
- The leading 1 is worth 16¹³, which is 4503599627370496
- Each of the thirteen F characters is 15, multiplied by the power of its own position
- Adding the fourteen terms gives 9007199254740991
Fourteen terms is the widest this sum ever gets, and it is the same ceiling the decimal pages hit at 9007199254740991 and the binary pages at fifty-three digits. Nothing about the method changes at this size — it is the same multiply-and-add, repeated fourteen times — which is the useful thing to take from the example.
Limitations
The input here is a hexadecimal string rather than a decimal one, so there is no decimal point to reject: characters outside 0 to 9 and A to F are refused. The input may be at most fourteen characters, which is 1FFFFFFFFFFFFF, and anything longer is refused with a message rather than truncated. Leading zeros are accepted and change nothing, and a leading minus sign produces a negative decimal result — the sum is computed for the digits and the sign is applied to the total. Case is not significant in the input, though the place value sum is always printed with uppercase letters. The table below lists the powers of sixteen from 16⁰ up to 16¹³ and is fixed, so it does not follow what you typed; it is there so the weight of any position can be looked up. Going the other way, from a decimal number to hexadecimal, is a separate page, and this one does no arithmetic on the result beyond the sum it prints.
Frequently asked questions
- How do I convert hex to decimal by hand?
- Write the powers of sixteen under the characters, starting at 1 on the right and multiplying by sixteen each step left, then multiply each character by the power beneath it and add the results. Letters have to be replaced first: A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15. For 2A3F that gives 2×4096 + 10×256 + 3×16 + 15, which is 10815.
- What do the letters A to F mean?
- They are the values ten to fifteen, in order: A is 10, B is 11, C is 12, D is 13, E is 14, F is 15. Base sixteen needs sixteen single characters and the decimal digits supply only ten, so six more symbols are needed and letters are the agreed convention. Each letter is a coefficient in exactly the same way a digit is, so an F is worth fifteen times whatever its position carries — fifteen in the last place, 240 one place to the left.
- What is the largest hexadecimal number I can convert here?
- Fourteen characters. 1FFFFFFFFFFFFF is the ceiling and it converts to 9007199254740991, which is the same boundary the decimal pages state as fifty-three binary digits. A longer string is refused with a message rather than truncated or rounded, because past that width a machine cannot hold neighbouring whole numbers apart and the answer could not be trusted.
- Why is FF equal to 255 and not 256?
- Because counting starts at 00, not at 01. Two hexadecimal characters give 256 different strings, running from 00 to FF, so the largest value they can represent is 255 — one less than the number of possibilities. The same off-by-one shows up in binary, where eight bits run from 0 to 255, which is why a byte's maximum is 255 in every language that has bytes.
- Is hex to decimal the same as hex to binary?
- No. Converting to binary is a substitution that needs no arithmetic: each character becomes four bits, and that is the whole method. Converting to decimal is a weighted sum, because the positions are worth powers of sixteen rather than powers of two — 2A3F is 2×4096 + 10×256 + 3×16 + 15, and the letters have to be turned into values before anything is multiplied. The binary result of the same string is 10101000111111, and the two answers are the same quantity written two ways.
- Why does the page print the powers of sixteen in a table?
- Because the powers are the weights every term of the sum is multiplied by, and looking them up is faster than working them out. The table runs from 16⁰ to 16¹³ and is exhaustive for this page: fourteen characters is the widest accepted input, so no accepted answer uses a position the table does not list. Reading it next to the sum in the result panel shows which weight belongs to which character.
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 the same quantity is written in several bases — Wolfram MathWorld (United States)
- Powers of two — the sequence that the powers of sixteen are every fourth term of, 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 — 中华人民共和国教育部