Computer Science
Basic

Hexadecimal to Decimal

Convert a hex number to decimal by positional weights.

Formula

d=∑hi×16id = \sum h_i \times 16^i

Variables

h_iHex digit
iPosition

Example

0x1F = 31

How it works

A hexadecimal number is a base-16 number system, so each digit represents a value multiplied by a power of 16 depending on its position. The rightmost digit has weight 16^0, the next has weight 16^1, then 16^2, and so on; the formula adds these weighted values to produce the decimal total. This works because positional numeral systems encode numbers by place value, just like decimal uses powers of 10.

When to use it

Use this when you need to convert hex values into ordinary decimal numbers, such as reading memory addresses, color codes, machine-level data, or programming outputs. It is also useful in computer science classes when comparing base-16 and base-10 representations.

Worked example, step by step

Convert 0x2A to decimal 0x2A = (2 × 16^1) + (A × 16^0) A = 10, so 0x2A = (2 × 16) + (10 × 1) = 32 + 10 = 42

Common mistakes to avoid

  • Forgetting that A, B, C, D, E, and F mean 10 through 15
  • Using the wrong position powers, especially starting from 16^1 instead of 16^0
  • Treating the digits as separate decimal numbers instead of weighted place values

Did You Know?

Hexadecimal packs four bits per digit, which is why colours and memory addresses are written in hex.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026