Math glossary

Hexadecimal Number System: Hex to Decimal and Binary Conversion

Learn base 16 place value, hex to decimal, binary and octal conversions, and hexadecimal arithmetic. See worked examples and common notation.

TL;DR

To convert hex to decimal, multiply each digit’s value by its power of 16, then add. Start with 16016^0 at the rightmost whole digit. The letters A through F represent 10 through 15.

Key Points

  • Hexadecimal is base 16, while decimal is base 10.
  • The whole-number places from right to left have weights 1,16,256,4096,…1,16,256,4096,\ldots.
  • Each place after the hexadecimal point has a negative power of 16.
  • A zero digit contributes no value but still holds its place.
  • The same hex digits can represent a signed value when a signed encoding and bit width are specified.

What does converting hex to decimal mean?

Hexadecimal writes numbers in base 16. Decimal writes the same values in base 10. The conversion changes the notation. It leaves the quantity unchanged. Longwood University’s number bases notes show how positional notation uses each digit’s value and place weight.

The digits 00 through 99 represent their usual values. Six letters supply the remaining values. Uppercase and lowercase letters mean the same thing here.

Hex digit Decimal value Hex digit Decimal value
0 0 8 8
1 1 9 9
2 2 A 10
3 3 B 11
4 4 C 12
5 5 D 13
6 6 E 14
7 7 F 15

After hexadecimal F comes hexadecimal 10, which means 1·16+0=161\cdot16+0=16 in decimal. A subscript such as 1016\mathrm{10}_{16} identifies the base. In programming, 0x10 is another way to mark the same base. The prefix identifies the notation and is not a digit.

How do you convert an entire hex number by hand?

  1. Convert each letter to a value from 10 through 15.
  2. Put 16016^0 below the rightmost digit before the point. Moving left, assign 161,162,…16^1,16^2,\ldots.
  3. Multiply the digit values by those place weights.
  4. Add the products.

For the three-digit numeral 3A716\mathrm{3A7}_{16}, the digits correspond to 3, 10, and 7.

3A716=3·162+10·161+7·160=768+160+7=93510.\mathrm{3A7}_{16}=3\cdot16^2+10\cdot16^1+7\cdot16^0 =768+160+7=935_{10}.
The hexadecimal digits 3, A and 7 matched to base-16 weights 256, 16 and 1
Convert A to 10 before multiplying by its place weight of 16. The three place contributions add to 935.

If the numeral is long, work left to right using a running total. Start at zero. For each digit, multiply the existing total by 16 and add the digit’s value. For 3A716\mathrm{3A7}_{16}, the successive totals are 33, 3·16+10=583\cdot16+10=58, then 58·16+7=93558\cdot16+7=935. Loyola Marymount’s numeric encoding notes and New Mexico State’s number systems guide connect these steps with ordinary place value.

How do hex fractions and signed values work?

For digits after the hexadecimal point, move right through 16−1,16−216^{-1},16^{-2}, and so on. The first fractional place is sixteenths and the second is 256ths. For example, A.416=10+4/16=10.2510\mathrm{A.4}_{16}=10+4/16=10.25_{10}. The decimal and fraction conversion guide gives the same place-value idea in base ten.

A plain leading minus sign negates the converted value. For example, −2A16=−4210-\mathrm{2A}_{16}=-42_{10}. A fixed-width binary encoding may use a bit pattern to store negative numbers without a written minus sign. Nanyang Technological University’s data representation notes explain why the bit width and two’s-complement convention matter.

For example, F616=24610\mathrm{F6}_{16}=246_{10} when read as an ordinary hexadecimal numeral. If the same digits are specified as an 8-bit two’s-complement pattern, the stored value is 246−256=−10246-256=-10. A simple conversion question uses the ordinary positive interpretation unless it gives another convention.

Why do hex, binary, and decimal conversions agree?

One hex digit corresponds to four binary digits because 16=2416=2^4. For instance, A has value 10 and maps to 101021010_2. Each group of four bits behaves as a single base-16 digit. The binary number system guide shows the same process using powers of 2.

One check is to convert the decimal result back by dividing by 16 and recording the remainders. For 935935, the remainders are 7, 10, and 3 in that order. Read them backward and convert 10 to A to recover 3A716\mathrm{3A7}_{16}.

Hex also encodes separate values in some contexts. In an RGB color such as #3A7FC1, the pairs 3A, 7F, and C1 represent three channels. Convert each pair separately to get 58, 127, and 193. The W3C color specification defines this notation.

How do you convert to hexadecimal and do arithmetic in base 16?

To convert a positive decimal integer to hex, divide by 16 until the quotient is zero. The remainder at each step is a digit between 0 and 15. Read the remainders in reverse order and replace 10–15 with A–F.

Decimal value being divided Quotient Remainder as a hex digit
428 26 C
26 1 A
1 0 1

Read up the last column to get 1AC16\mathrm{1AC}_{16}. The check is 1·256+10·16+12=4281\cdot256+10\cdot16+12=428. For zero, the hex result is 0 without any divisions. For binary conversion, partition whole bits into groups of four from the right. Pad only the leftmost group with leading zeros if necessary. For instance, 110101121101011_2 becomes 0110 101120110\ 1011_2, which gives 6B16\mathrm{6B}_{16}.

To convert a whole hex number to octal, first convert every hex digit to four bits. Then regroup the binary number into sets of three from the right, since 8=238=2^3. For instance, 3A16=0011 10102\mathrm{3A}_{16}=0011\ 1010_2, which can be regrouped as 000 111 0102000\ 111\ 010_2 to give 72872_8. Both numerals equal 581058_{10}.

Hex addition carries at 16. For EF16+3616\mathrm{EF}_{16}+\mathrm{36}_{16}, start with F+6\mathrm F+6. The sum 21 equals 16+516+5, so write 5 and carry 1. Next E+3+1=18\mathrm E+3+1=18 equals 16+216+2, so write 2 and carry 1 again. The result is 12516\mathrm{125}_{16}. In subtraction, a borrow adds 16 to the current column and reduces the next column by 1. For example, 1B216−2F16=18316\mathrm{1B2}_{16}-\mathrm{2F}_{16}=\mathrm{183}_{16}.

Where is hexadecimal useful?

UC Berkeley’s course notes compare hexadecimal with binary and decimal. The four-bits-per-digit mapping makes a byte of eight bits fit into two hex digits. The unsigned patterns range from 0016\mathrm{00}_{16} to FF16\mathrm{FF}_{16}, or 0 to 255. Two bytes occupy up to four hex digits when representing their combined unsigned value. A fixed-width display may retain leading zeros to show the width.

For a design colour such as #0840B0, first split the pairs: 08, 40, and B0. They mean red 8, green 64, and blue 176 in 8-bit RGB. Keeping the leading zero on 08 preserves the channel's two-character width. For other bit patterns, the surrounding format tells you whether the digits represent one integer or several values.

Examples of Hex to Decimal Conversion

Example 1

Convert B16\mathrm B_{16}.

  1. The digit B represents 11.
  2. It occupies the ones place, 160=116^0=1.
  3. Its decimal value is 11.

Example 2

Convert 2F16\mathrm{2F}_{16}.

  1. Multiply the first digit by 16, giving 2·16=322\cdot16=32.
  2. The digit F contributes 15 in the ones place.
  3. The result is 32+15=4732+15=47.

Example 3

Convert 3A716\mathrm{3A7}_{16}.

  1. Match the digits with place values 256, 16, and 1.
  2. Compute 3(256)+10(16)+7(1)3(256)+10(16)+7(1).
  3. Add 768+160+7768+160+7 to get 935.

Example 4

Convert 1C.816\mathrm{1C.8}_{16}.

  1. The whole-number part is 1(16)+12=281(16)+12=28.
  2. The 8 after the point contributes 8/16=0.58/16=0.5.
  3. Add to get 28.51028.5_{10}.

Example 5

Convert A0116\mathrm{A01}_{16}.

  1. The zero in the middle may look skippable. It contributes no amount, but the A remains in the 16216^2 place.
  2. Compute 10(256)+0(16)+1(1)10(256)+0(16)+1(1).
  3. The result is 2,561.

Example 6

Read F616\mathrm{F6}_{16} as an unsigned numeral and as a specified 8-bit two’s-complement value.

  1. Compute 15(16)+6=24615(16)+6=246.
  2. That is its unsigned value. In an 8-bit two’s-complement interpretation, 246 falls in the upper half of the 256 possible patterns.
  3. Subtract 256 to recover −10-10.

What mistakes should you check for?

Mistake 1: Starting with 16116^1 at the rightmost whole digit

The units place uses 160=116^0=1. For 2F16\mathrm{2F}_{16}, F contributes 15. Giving it weight 16 makes the entire result sixteen times too large.

Mistake 2: Accepting a letter beyond F

For ordinary hexadecimal notation, only digits 0 through 9 and letters A through F are valid. A string such as 2G needs correction or a different declared base.

Mistake 3: Reading the same digits in the wrong base

Decimal 10 means ten. Hexadecimal 10 means sixteen. Preserve the base marker when writing a conversion intermediate.

Try It Yourself

  1. Convert FF16\mathrm{FF}_{16}.
  2. Convert 1A316\mathrm{1A3}_{16}.
  3. Convert A.416\mathrm{A.4}_{16}.

Answers and Reasoning

  1. 15(16)+15=25515(16)+15=255.
  2. 1(256)+10(16)+3=4191(256)+10(16)+3=419.
  3. 10+4/16=10.2510+4/16=10.25.

Questions About Hex to Decimal

Does 0xFF equal FF?

Yes, when FF already refers to a hexadecimal number. Both then mean 255 in decimal. The prefix just makes the base explicit.

Are hexadecimal conversion and decoding text the same task?

Hex-to-decimal conversion interprets a numeral’s value. Decoding text requires a character encoding that specifies what bytes represent. One hex string can require different interpretation depending on that convention.

Conclusion

  • Map A through F to the values 10 through 15.
  • Keep every digit in its correct place and start the rightmost whole digit at 16016^0.
  • Use negative place powers for fractions and read signed bit patterns only under their stated encoding.

Read More

Research Behind This Article

  1. Longwood University, CMSC 121: Number Bases. Longwood
  2. Loyola Marymount University, Numeric Encoding. LMU
  3. New Mexico State University, Numbers and Numbering Systems. NMSU
  4. Nanyang Technological University, A Tutorial on Data Representation. NTU
  5. World Wide Web Consortium, CSS Color Module Level 4: Hexadecimal Notation. W3C
  6. University of California, Berkeley, CS 61C — Binary, Decimal, Hex. UC Berkeley