Calcylator
Hex To Decimal

Hex to decimal:
reading base 16 one digit at a time

Hexadecimal is just a compact way to write binary. Once you know the digit values and the place weights, any hex number opens up in a few lines.

Calcylator Editorial Team

Updated · 5 min read

What base 16 means and why people use it

Everyday numbers are written in base 10, where each position is worth ten times the one to its right. Hexadecimal works the same way but with sixteen as the multiplier, so it needs sixteen different symbols. The digits 0 to 9 cover the first ten values, and the letters A to F cover 10 to 15.

Programmers favour hex because it lines up neatly with binary. One hex digit stands for exactly four bits, so a byte, eight bits, is always two hex digits. A long binary string such as 0010 1111 collapses into 2F, which is far easier to read and copy without error.

You see hex in memory addresses, error codes, MAC addresses, web colours such as #1E90FF and character code charts. Converting to decimal lets you reason about size and ranges using numbers you already feel comfortable with.

Digit values and place weights

Letters A to F stand for 10 to 15
Hex digitABCDEF
Decimal value101112131415

Place weights grow by a factor of 16 as you move left. The rightmost digit is worth 1, the next 16, then 256, then 4,096 and 65,536.

Place values in hexadecimal
Position (from right)01234
Weight1162564,09665,536
Written as16⁰16¹16²16³16⁴
Hex to decimal =Σ (digit × 16^position)
digit:
value 0 to 15 of each hex character
position:
counted from the right, starting at 0
Σ:
sum over every digit

Worked example: converting 1A3F

Write the digits and their positions from the right. 1 is in position 3, A in position 2, 3 in position 1 and F in position 0. Replace letters with their decimal values: A is 10 and F is 15.

  • Hex number

    1A3F

  • 1 × 16³

    1 × 4,096 = 4,096

  • A × 16²

    10 × 256 = 2,560

  • 3 × 16¹

    3 × 16 = 48

  • F × 16⁰

    15 × 1 = 15

  • Sum

    4,096 + 2,560 + 48 + 15

Decimal value

6,719

Check: 6,719 ÷ 16 leaves remainder 15 (F), confirming the last digit.

The smaller case from the same family is 2F. That is 2 × 16 + 15 = 47, which is the typical first exercise because it needs only one multiplication.

A shortcut that avoids powers of 16

Raising 16 to a power is slow by hand. A cleaner way is to work left to right: start with the first digit, then for each following digit multiply the running total by 16 and add the next digit. This is called Horner's method and it only needs small numbers.

  1. Take the first digit: 1.
  2. Multiply by 16 and add the next digit A (10): 1 × 16 + 10 = 26.
  3. Multiply by 16 and add 3: 26 × 16 + 3 = 419.
  4. Multiply by 16 and add F (15): 419 × 16 + 15 = 6,719.

The answer matches the place-value method, which is a good way to cross-check a conversion. If the two disagree, one of the digits has been read wrong, most often a B for an 8 or a D for 0.

Where you will meet hex numbers

Web colours are three hex pairs: red, green and blue, each from 00 (0) to FF (255). The colour #1E90FF is 1E = 30, 90 = 144 and FF = 255, which is rgb(30, 144, 255), a bright blue. Because each pair is one byte, the whole colour holds 16,777,216 possible values.

Memory and file sizes use hex when they show offsets. An offset of 3E8 is 3 × 256 + 14 × 16 + 8 = 1,000 in decimal. A two-byte value FFFF is 65,535, and a four-byte FFFFFFFF is 4,294,967,295.

Network engineers see hex in IPv6 addresses and MAC addresses. An IPv4 address like 192.168.0.1 can be written in hex as C0.A8.00.01, with C0 = 192 and A8 = 168.

Going the other way, and the binary link

Converting from decimal back to hex is repeated division by 16, writing down the remainders from the last one to the first. It is useful for checking your first conversion, because a round trip should return the number you started with.

  1. Divide 6,719 by 16: quotient 419, remainder 15, which is F.
  2. Divide 419 by 16: quotient 26, remainder 3.
  3. Divide 26 by 16: quotient 1, remainder 10, which is A.
  4. Divide 1 by 16: quotient 0, remainder 1.

Reading the remainders from bottom to top gives 1A3F, matching the number we began with. Each step peels off one hex digit, starting from the least significant.

The link to binary explains why hex is so popular. Every hex digit expands to exactly four bits, so 1A3F becomes 0001 1010 0011 1111. You can convert between hex and binary without any arithmetic by replacing each digit with its four-bit pattern, and then go from binary to decimal only if you need to. Conversions between hex and decimal are the part that needs real calculation, which is why a tool or a methodical routine is worth having.

Mistakes that give the wrong decimal

  • Treating A to F as 1 to 6 instead of 10 to 15.
  • Starting the exponent at 1 instead of 0, which multiplies every digit by an extra 16.
  • Counting positions from the left; the weight is set by the distance from the right-hand end.
  • Forgetting that signed numbers differ: the byte FF is 255 unsigned, but −1 in two's complement.
  • Reading lowercase letters as different values; a to f mean the same as A to F.

When the result seems unreasonable, check the digit count. A two-digit hex number can never exceed 255, and a three-digit one cannot exceed 4,095. If your answer is larger, a power was misapplied.

Common questions

How do you convert hex to decimal?

Multiply each hex digit by 16 raised to its position, counting from 0 at the right, and add the results. Use A = 10 through F = 15. For example, 2F = 2 × 16 + 15 = 47, and 1A3F = 6,719.

What is 2F in decimal?

2F is 47. The 2 is in the sixteens place, so it is worth 2 × 16 = 32, and F is 15 in the ones place. Adding 32 and 15 gives 47. In binary, the same number is 0010 1111.

What is FF in decimal?

FF is 255. The first F is 15 × 16 = 240 and the second F is 15 × 1 = 15, so the sum is 255. It is the largest value a single byte can hold, which is why colour channels run from 0 to 255.

Why do letters appear in hexadecimal?

Base 16 needs sixteen single-character digits, but we only have ten numerals. The letters A to F fill the remaining six values, with A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. Case does not matter.

How do you convert a hex colour code to RGB?

Split the six digits into three pairs and convert each pair from hex to decimal. For #1E90FF, 1E is 30, 90 is 144 and FF is 255, so the colour is rgb(30, 144, 255). Each pair ranges from 0 to 255.

Was this guide helpful?

Continue reading

View all blogs