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 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 .
- 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 through 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 in decimal. A subscript such as 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?
- Convert each letter to a value from 10 through 15.
- Put below the rightmost digit before the point. Moving left, assign .
- Multiply the digit values by those place weights.
- Add the products.
For the three-digit numeral , the digits correspond to 3, 10, and 7.
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 , the successive totals are , , then . 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 , and so on. The first fractional place is sixteenths and the second is 256ths. For example, . 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, . 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, 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 . 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 . For instance, A has value 10 and maps to . 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 , the remainders are 7, 10, and 3 in that order. Read them backward and convert 10 to A to recover .
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 . The check is . 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, becomes , which gives .
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 . For instance, , which can be regrouped as to give . Both numerals equal .
Hex addition carries at 16. For , start with . The sum 21 equals , so write 5 and carry 1. Next equals , so write 2 and carry 1 again. The result is . In subtraction, a borrow adds 16 to the current column and reduces the next column by 1. For example, .
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 to , 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 .
- The digit B represents 11.
- It occupies the ones place, .
- Its decimal value is 11.
Example 2
Convert .
- Multiply the first digit by 16, giving .
- The digit F contributes 15 in the ones place.
- The result is .
Example 3
Convert .
- Match the digits with place values 256, 16, and 1.
- Compute .
- Add to get 935.
Example 4
Convert .
- The whole-number part is .
- The 8 after the point contributes .
- Add to get .
Example 5
Convert .
- The zero in the middle may look skippable. It contributes no amount, but the A remains in the place.
- Compute .
- The result is 2,561.
Example 6
Read as an unsigned numeral and as a specified 8-bit two’s-complement value.
- Compute .
- That is its unsigned value. In an 8-bit two’s-complement interpretation, 246 falls in the upper half of the 256 possible patterns.
- Subtract 256 to recover .
What mistakes should you check for?
Mistake 1: Starting with at the rightmost whole digit
The units place uses . For , 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
- Convert .
- Convert .
- Convert .
Answers and Reasoning
- .
- .
- .
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 .
- Use negative place powers for fractions and read signed bit patterns only under their stated encoding.
Read More
Research Behind This Article
- Longwood University, CMSC 121: Number Bases. Longwood
- Loyola Marymount University, Numeric Encoding. LMU
- New Mexico State University, Numbers and Numbering Systems. NMSU
- Nanyang Technological University, A Tutorial on Data Representation. NTU
- World Wide Web Consortium, CSS Color Module Level 4: Hexadecimal Notation. W3C
- University of California, Berkeley, CS 61C — Binary, Decimal, Hex. UC Berkeley