Hexadecimal numbers are a type of number which use the normal digits and letters A-F. In order to understand what these numbers mean and how they work, we will need to introduce a few concepts. In the sections below, we'll introduce the concept of number bases, the discuss how hexadecimal numbers fit into this, how to work with them, and how to convert from hexadecimal back to normal numbers.
A number base is the number of digits a numeric system uses to denote numbers. Common, every day numbers and math systems use 10 digits, the digits 0-9, to represent numbers, making it a system of base 10. This is referred to as the decimal system, the prefix dec standing for 10. Most numbers will not use all 10 digits, but they are still considered base 10 numbers because the 10 digits are still "available". Binary numbers, numbers of which only have the digits 0 and 1, form a system of base 2. The binary number 10 is equal to the the decimal number 2. When discussing numbers of different bases at the same time, we can use a subscript to denote which base the number is declared as; the last sentence can be summarized as: 102 = 210. Note that the subscript number itself will always be base 10. In this article, we will be discussing base 2, base 10, and base 16, but note that any other positive integer greater than or equal to 2 can also be used as a base.
The hexadecimal system is a system which has 16 digits, making it a base 16 system. The prefix hex stands for 6, combined with the prefix dec stands for 16. The available digits are 0-9 and A-F. It uses the same 10 digits as the decimal system, then uses the additional A-F as the remaining 6 digits. The decimal number 10 is equal to the hexadecimal number A, and the hexadecimal number 10 is equal to the decimal number 16. More concisely: A16 = 1010 and 1016 = 1610. Hexadecimal numbers are useful for certain programming needs, such as color specification, because 16 is a power of 2, so anything which can be represented with binary numbers can also easily be represented by hexadecimal; it's much easier to convert between binary and hexadecimal than it is to convert between binary and decimal.
Number Values and Operations in Different Bases
The only difference between binary numbers, decimal numbers, and hexadecimal numbers is the number of digits available to denotate a number. Each system can represent the same number values and perform the same operations of addition, multiplication, exponentiation, and all others. In other words, the difference is in the notation of the numbers only, not the numbers themselves or operations over them. Furthermore, any number which can be expressed in one base can be expressed in all bases. Therefore, the choice of which base to use in any given situation should be based on what is required for notation, data transfer, or data storage purposes.
The Number 10
In any base, the value of the number denoted by "10" is equal to the number of digits in that base. We can consider "10" to be the first occurence of an overflow, where we run out of digits and have no choice but to use a second digit. The number "100" is the second overflow; we run out of digits again, so we must use a third one to continue declaring numbers. In the general sense, a number which is denoted as "1" followed by x number of zeros in a base b will be equal to the value of bx. The table below shows the values of "100" and "1000" for bases 2, 10, and 16 converted to base 10.
|Base||Decimal Value of "10"||Decimal Value of "100"||Decimal Value of "1000"|
|2||102 = 210 = 210110||1002 = 410 = 210210||10002 = 810 = 210310|
|10||1010 = 1010 = 1010110||10010 = 10010 = 1010210||100010 = 100010 = 1010310|
|16||1016 = 1610 = 1610110||10016 = 25610 = 1610210||100016 = 409610 = 1610310|
Converting to Base 10
Understanding how to convert a hexadecimal number to base 10 is not crucial towards understanding the concepts of bases and hexadecimal numbers, but we will give a brief overview nonetheless. As stated above, a number marked as "10", "1000", or similar, is equal to the base taken to the power of the number of zeros. This hints at the fact that the base and amount of digits in a number have a strong relationship with the value of the number itself. As the number of digits available increases, the number of digits we need to use to represent any particular number decreases. For example, we can represent the number 409510, which uses 4 digits in base 10, using only 3 digits in base 16 as the number fff16, whereas we would need 12 digits in base 2 as the number 1111111111112. The table below shows a series of numbers as they are denoted in each base.
The value of a number in base b with digits dn....d1d0 can be described as d0 ⋅ b0 + d1 ⋅ b1 .... dn ⋅ bn. Starting with 0 instead of 1 makes the math a bit simpler. That equation may look tricky at first, so let's apply it to something that is already in base 10 to see how it works. If we take the number 894510, we see that digit 0 is 5, digit 1 is 4, digit 2 is 9, and digit 3 is 8. If we plug these into the formula, we will have: 5 ⋅ 100 + 4 ⋅ 101 + 9 ⋅ 102 + 8 ⋅ 103 = 5 + 40 + 900 + 8000 = 8945.
Now let's apply this concept to a hexadecimal number: the number A43C16 has 4 digits. C is digit 0, 3 is digit 1, 4 is digit 2, and A is digit 3. If we run the equation above, we will get: 12 ⋅ 160 + 3 ⋅ 161 + 4 ⋅ 162 + 10 ⋅ 163 = 4204410. In the case of hexadecimal, or any base larger than 10, we have to convert each digit to its base 10 value before performing the calculation. In this example, we converted C to 12 and A to 10. The approach is to take the value of each digit, converts it to base 10, then multiply it by the base taken to the power of the digit position.