Formula Bro

Math and physics formulas, explained like you are new.


Hexadecimal Number Value

In one sentence: Hexadecimal counts in sixteens using the digits 0 to 9 and the letters A to F, and this formula turns a hex number into the ordinary number it stands for.

N=∑i=0n−1di⋅16iN = \sum_{i=0}^{n-1} d_i \cdot 16^{i}

Read it out loud: “N equals the sum, for every position i from 0 up to n minus 1, of d sub i times 16 to the power of i. N is the ordinary decimal number. n is how many hex digits there are. i is the position of a digit, counted from zero on the right. d sub i is the digit in position i, a value from 0 to 15. The 16 with i as a small raised number means sixteen multiplied by itself i times. The sigma sign means add up all the terms.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

A number system and its base

A number system is a way of writing numbers with a fixed set of digit symbols. The base is how many different digit symbols it uses. Our everyday system is base 10, with the digits 0 to 9. Binary is base 2, with digits 0 and 1. Hexadecimal is base 16, with sixteen digit symbols: 0 to 9 and then A to F. Each place in a number is worth the base raised to a power.

Powers of sixteen, like 16216^{2}

A power is a number multiplied by itself a set number of times, and the small raised number, the exponent, says how many times. So 162=16×16=25616^{2} = 16 \times 16 = 256 and 161=1616^{1} = 16. Any number to the power 0 is 1, so 160=116^{0} = 1. The places of a hex number are 1, 16, 256, 4096 and so on, and each place is sixteen times the place on its right.

Letters used as digits, A to F

Hexadecimal needs sixteen digit symbols, so after 0 to 9 it borrows the letters A to F. These letters are digits, not words. A means 10, B means 11, C means 12, D means 13, E means 14 and F means 15. So the hex digit F is worth fifteen, not six, and the hex number 1A is one sixteen plus ten ones, which is 26.

Nibbles, bytes and bits

A bit is one 0 or 1. A nibble is a group of four bits, and a byte is a group of eight bits, which is two nibbles. One hex digit stands for exactly one nibble, so two hex digits stand for exactly one byte. This is the main reason hexadecimal is used for computer data.

The 0x prefix

Programmers often start a hex number with the two characters 0x, as in 0x2F. The 0x is a label that says the digits are hexadecimal. It is not one of the digits and it is not counted in the value, so 0x2F and 2F are the same number.

The sum sign ∑\sum and the position counter ii

The Greek capital letter sigma, ∑\sum, means add up a list of terms. The counter ii starts at 0 under the sign and stops at n−1n - 1 above it, so it takes each position in turn. The formula writes the same thing as one term for each digit, with a plus sign between them.

What each symbol means

SymbolMeaning

NN

The ordinary decimal number that the hex digits stand for. It is a plain count with no unit. The hex number 2F stands for N=47N = 47, which means forty-seven.

nn

How many hex digits the number has. It is a count with no unit. The number 2F has two digits, so n=2n = 2, and a number written with eight hex digits has n=8n = 8.

ii

The position of one digit, counted from 0 on the right. Position 0 is the rightmost digit. It has no unit, and for a two-digit number the positions are 0 and 1.

did_i

The digit in position ii, a value from 0 to 15 with no unit. The symbols 0 to 9 are worth 0 to 9, and the letters A, B, C, D, E and F are worth 10, 11, 12, 13, 14 and 15.

16i16^{i}

The place value of position ii: how much one unit in that place is worth. It has no unit. The place values are 1, 16, 256, 4096 and so on, and each one is sixteen times the place on its right.

∑i=0n−1\sum_{i=0}^{n-1}

The sum sign, which means add up the terms for every position from 0 up to n−1n - 1. It has no unit. In plain words, go through every digit from the right to the left, work out its value and add all the values together.

The formula piece by piece

16i16^{i}

The place value of one position. The base is sixteen, so the place values are 1 on the right, then 16, then 256, then 4096 for each place further left. Each place is worth sixteen times the place on its right.

did_{i}

The digit in that same position, from 0 to 15. It is written as 0 to 9 or as the letters A to F, and the letter is converted to its value first. A digit F in a place counts as fifteen units of that place.

di⋅16id_{i} \cdot 16^{i}

Multiply the digit by its place value. A digit of 2 in the sixteens place is worth 2×16=322 \times 16 = 32, and a digit F in the ones place is worth 15×1=1515 \times 1 = 15. Each digit gives its full worth for its place.

∑i=0n−1di⋅16i\sum_{i=0}^{n-1} d_{i} \cdot 16^{i}

Add those products for every digit position, from position 0 on the right up to position n−1n - 1 on the left. The total is the ordinary number that the hex digits stand for.

N=∑i=0n−1di⋅16iN = \sum_{i=0}^{n-1} d_i \cdot 16^{i}

The whole formula in one sentence: the ordinary number N equals the total you get by adding, for every digit position, that digit multiplied by its place value in base sixteen.

What the formula is doing, and why

What goes in and what comes out. You give the formula a hex number, written with the digits 0 to 9 and the letters A to F. It gives back the ordinary decimal number. For the hex number 2F the answer is 47. The formula reads every digit, multiplies it by the place value of its position, and adds the results.

Why sixteen? Each place is worth sixteen times the place on its right, so the places are 1, 16, 256 and 4096. Sixteen equals 242^{4}, a power of two, and that is why each hex digit lines up with exactly four bits. Hex is therefore a short way of writing binary, four bits at a time.

Why do the digits run up to 15? Each digit in a base-16 place can be any value from 0 to 15, which is sixteen possible values, so sixteen digit symbols are needed. The letters A to F cover the values 10 to 15. The largest number with nn hex digits is 16n−116^{n} - 1. For two digits that is 162−1=25516^{2} - 1 = 255, which is why one byte fits in exactly two hex digits, from 00 to FF.

When it applies. The formula is for numbers written in base sixteen. The 0x prefix in front of a number, such as 0x2F, tells you the digits are hexadecimal, but the prefix is not part of the value. Hex is used because it is much shorter than binary, and converting between hex and binary is quick, because each digit maps to four bits.

An everyday picture

Think of an odometer whose wheels carry sixteen marks, the digits 0 to 9 and then A to F, instead of ten. When a wheel passes F, it goes back to 0 and moves the wheel on its left forward by one step, in the same way that a decimal odometer carries after 9. Each wheel is worth sixteen times the wheel on its right.

Worked example: Reading the web color #FF8800

A web page sets a color with the hex code #FF8800. The # sign tells the browser that a color code follows, and it is not part of the value. The six digits split into three pairs, one for each light channel: red is FF, green is 88 and blue is 00. Each pair has two hex digits, which is one byte, so each channel runs from 0 to 255.

  1. Split the code into pairs. The six digits are FFFF, 8888 and 0000. Each pair has two hex digits, and each pair stands for one byte. We read each pair with the formula, using the place values 16 on the left and 1 on the right.
  2. Read the red pair FF. The left F is in the 16 place and is worth 15×16=24015 \times 16 = 240. The right F is in the 1 place and is worth 15×1=1515 \times 1 = 15. Adding them gives 240+15=255240 + 15 = 255, the largest value a byte can hold, which means red at full strength.
  3. Read the green pair 88. Each 8 stands for eight units. The left 8 is in the 16 place and is worth 8×16=1288 \times 16 = 128, and the right 8 is in the 1 place and is worth 8. Adding gives 128+8=136128 + 8 = 136. In binary, 88 is 1000100010001000, which is the same 136. Green is a little over half of full strength.
  4. Read the blue pair 00. Both digits are 0, so each product is 0×16=00 \times 16 = 0 and 0×1=00 \times 1 = 0. The total is 0, which means no blue light at all. A zero digit adds nothing, whatever its place.
  5. Read the whole six-digit code as one number. Treated as one number, FF8800 has six positions, and the top pair FF sits at places 16416^{4} and 16516^{5}. Its value is 255×164+136×162=16,746,496255 \times 16^{4} + 136 \times 16^{2} = \text{16,746,496}. A program may store the color as this single number, and it is read back by splitting it into the same three pairs.
  6. Check the largest pair. The largest pair is FF, which is 162−1=25516^{2} - 1 = 255, and the smallest is 00, which is 0. Every channel of a web color therefore has 256 possible strengths, from 0 to 255. That is exactly one byte per channel.

Answer: The color #FF8800 has red 255, green 136 and blue 0, which is a bright orange. Read as one ordinary number, the six hex digits stand for 16,746,496.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

Why do programmers use hex instead of binary?

Hex is shorter. One hex digit stands for four bits, so a 32-bit number fits in eight hex digits, while writing it in binary takes 32 digits. Hex also converts to and from binary one digit at a time.

Why base 16 and not base 10?

Sixteen is 242^{4}, a power of two, so each hex digit lines up with exactly four bits. Base ten does not line up with binary in that way.

How do I convert hex to decimal?

Multiply each digit by its place value, which is a power of 16, and add the results. For example, 2F2F gives 2⋅16+15=472 \cdot 16 + 15 = 47.

Sources

  1. Hexadecimal, Wikipedia
  2. Positional notation, Wikipedia

| All Computer Science formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: computer-science/hexadecimal-number-value.md.