Hexadecimal Numbers
The hexadecimal (or base 16) number system is a positional number system that represents numeric values using sixteen symbols – 0 to 9 for the values zero to nine, and A,B,C,D.E and F to represent the numbers ten to fifteen. For this reason, it is said to have a radix of 16. Hexadecimal numbers are expressed as a series of one or more hexadecimal digits, followed by a lower-case "h" or occasionally by the subscript 16 to indicate that they are in fact hexadecimal (base 16) numbers. Here is the decimal number 165 expressed as a hexadecimal number:
A5h
Like the decimal system with which we are familiar, the position of each digit within a hexadecimal number determines its value. Whereas each position in a decimal number represents some power of 10, however, each position in a hexadecimal number represents a power of 16. The table below shows the numbers 0 to 63 (to base 10) as hexadecimal numbers.
| Hex | Dec | Hex | Dec | Hex | Dec | Hex | Dec |
| 0 | 0 | 10 | 16 | 20 | 32 | 30 | 48 |
| 1 | 1 | 11 | 17 | 21 | 33 | 31 | 49 |
| 2 | 2 | 12 | 18 | 22 | 34 | 32 | 50 |
| 3 | 3 | 13 | 19 | 23 | 35 | 33 | 51 |
| 4 | 4 | 14 | 20 | 24 | 36 | 34 | 52 |
| 5 | 5 | 15 | 21 | 25 | 37 | 35 | 53 |
| 6 | 6 | 16 | 22 | 26 | 38 | 36 | 54 |
| 7 | 7 | 17 | 23 | 27 | 39 | 37 | 55 |
| 8 | 8 | 18 | 24 | 28 | 40 | 38 | 56 |
| 9 | 9 | 19 | 25 | 29 | 41 | 39 | 57 |
| A | 10 | 1A | 26 | 2A | 42 | 3A | 58 |
| B | 11 | 1B | 27 | 2B | 43 | 3B | 59 |
| C | 12 | 1C | 28 | 2C | 44 | 3C | 60 |
| D | 13 | 1D | 29 | 2D | 45 | 3D | 61 |
| E | 14 | 1E | 30 | 2E | 46 | 3E | 62 |
| F | 15 | 1F | 31 | 2F | 47 | 3F | 63 |
The decimal number 39 expressed as a hexadecimal number (27h) is therefore:
2 x 161 + 7x160 (32 + 7 = 39)
The hexadecimal digit in the right-most position in any hexadecimal whole number holds the smallest value (with a maximum value of 15). The left-most hexadecimal digit has a maximum value that reflects its position relative to the right-most digit, and will be a multiple of some power of 16 greater than 0. The value of the left-most hexadecimal digit (assuming that we ignore leading zeros) always exceeds the combined value of all the digits to the right of it. For this reason, the overall magnitude of a hexadecimal number is always determined by the position of the left-most digit.
Fractions can also be represented using hexadecimal digits, as can real (fractional) numbers. Like real numbers to base 10, the fractional part of a hexadecimal number follows a period. In the decimal number system we call this a decimal point, but in the hexadecimal number system we call it a hexadecimal point. In the decimal system, the numeral in the first position following the decimal point is multiplied by 10-1 (0.1), the digit in the second position following the decimal point is multiplied by 10-2 (0.01), and so on. The fractional part of a hexadecimal number works on the same principle, except that the digit in the first position following the binary point is multiplied by 16-1 (0.0625 to base 10), the digit in the second position following the binary point is multiplied by 16-2 (0.00390625 to base 10), and so on. Note that, whereas each successive positive power of 16 has sixteen times the value of its predecessor, each successive negative power of 16 has one sixteenth the value of its predecessor. The anatomy of a real hexadecimal number is illustrated below.
The anatomy of a real hexadecimal number
Converting between decimal and hexadecimal
One method that can be used to convert a decimal number to its hexadecimal equivalent is to carry out integer division using 16 as the divisor. The number to be converted is divided by 16, and the remainder is written in the right-most position (as a hexadecimal digit). The integer result of the division is then divided by 16 again, and the remainder is written (again as a hexadecimal digit) to the left of the hexadecimal digit obtained in the previous step. This process is repeated until the integer result of the division is zero. An example will serve to illustrate the process. To convert the number 13,33710 to hexadecimal, proceed as follows:
| Integer division | Integer result | Remainder | Hex |
| 13,337 / 16 | 833 | 9 | 9h |
| 833 / 16 | 52 | 1 | 1h |
| 52 / 16 | 3 | 4 | 4h |
| 3 / 16 | 0 | 3 | 3h |
The number 13,33710 expressed as a hexadecimal number is therefore 3419h. You can carry out a relatively simple process to convert the number back to decimal (and at the same time confirm that the answer we obtained is correct) by multiplying each decimal digit by the appropriate power of 16 and adding the resulting decimal values together, as follows:
(3 x 163) + (4 x 162) + (1 x 161) + (9 x 160)
= (3 x 4096) + (4 x 256) + (1 x 16) + (9 x 1)
= 12,288 + 1,024 + 16 + 9
= 13,33710
Converting between binary and hexadecimal
Converting a hexadecimal number to binary is relatively easy, since each hexadecimal digit can be represented by a group of four binary digits. Converting hexadecimal numbers to binary is thus simply a matter of replacing each digit in the hexadecimal number with its four-digit binary representation. For example, the hexadecimal number 5E7Ah can be translated as follows:
5 = 0101
E = 1110
7 = 0111
A = 1010
So the binary equivalent of 5E7Ah = 0101111001111010. The hexadecimal digits, together with their four-digit binary equivalents, are listed in the table below.
| Hex | Binary | Hex | Binary |
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | A | 1010 |
| 3 | 0011 | B | 1011 |
| 4 | 0100 | C | 1100 |
| 5 | 0101 | D | 1101 |
| 6 | 0110 | E | 1110 |
| 7 | 0111 | F | 1111 |
Because it is so easy to represent groups of four binary digits using hexadecimal digits, the hexadecimal number system is frequently used to represent binary values in the fields of computing and digital electronics. Byte values, which can represent decimal numbers in the range 0 to 255, are often expressed using a pair of hexadecimal digits in the range 00h to FFh. Hexadecimal numbers are also commonly used to represent memory addresses in assembly language programs. Converting binary numbers to their hexadecimal equivalent is simply a matter of converting each group of four binary digits to its hexadecimal equivalent. For example, the binary number 1011100111010101 can be translated as follows:
1011 = B
1001 = 9
1101 = D
0101 = 5
So the hexadecimal equivalent of 1011100111010101 = B9D5h.