Hexadecimal (Base16 )
Why learn the Hexadecimal (Base16 ) number system?
Binary numbers can be cumbersome to work with as they get large. A shorthand notation is useful when working with a large string of 0's and 1's as seen in binary. Although people are most familiar with decimal because it's used on a daily basis, it does not map well to binary. Hexadecimal is extremely useful as a shorthand for binary because one single hexadecimal digit can represent four binary digits or bits. Four binary digits or bits equal a half byte or nibble. A byte can be represented with two hexadecimal digits instead of eight binary digits. For this reason, hexadecimal digits are often used to represent byte values in computer systems and networks.
| Binary Value |
Hexadecimal Value |
Decimal Value |
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | A | 10 |
| 1011 | B | 11 |
| 1100 | C | 12 |
| 1101 | D | 13 |
| 1110 | E | 14 |
| 1111 | F | 15 |
What is the Hexadecimal
(Base16 ) number
system?
The hexadecimal base16 number system, often called "hex", consists of two elements:
| Hexadecimal Digits |
1st Four Columns in Decimal |
Hexadecimal Column | ||||
| 0-9 and A-F |
or | 163 | 162 | 161 | 160 |
Hexadecimal 123B16 converted to Decimal
equals |
| 4096 | 256 | 16 | 1 | |||
|
Hexadecimal Column Conversion to Binary | ||||
|
Hexadecimal 123B16 converted to Binary = 00010010001110112 | ||||
| Each Hexadecimal Digit | 1 | 2 | 3 | B |
| = Four Binary Digits or Bits | 0001 | 0010 | 0011 | 1011 |
How does the Hexadecimal (Base16 ) number system work?
Counting in Hexadecimal (Base16)
The standard unit of storage in computing is a byte. A byte consists of 8 bits or 2 nibbles (4 bits each). A byte can contain the decimal values 0-255 for a total of 256 different numbers or bit combinations. Below is a table that counts through all the possible bit combinations in a byte (decimal values 0-255, hexadecimal values 00-FF).
| Decimal Base10 |
Hexadecimal Base16 |
Decimal Base10 |
Hexadecimal Base16 |
Decimal Base10 |
Hexadecimal Base16 |
Decimal Base10 |
Hexadecimal Base16 |
| 0 | 00 | 64 | 40 | 128 | 80 | 192 | C0 |
| 1 | 01 | 65 | 41 | 129 | 81 | 193 | C1 |
| 2 | 02 | 66 | 42 | 130 | 82 | 194 | C2 |
| 3 | 03 | 67 | 43 | 131 | 83 | 195 | C3 |
| 4 | 04 | 68 | 44 | 132 | 84 | 196 | C4 |
| 5 | 05 | 69 | 45 | 133 | 85 | 197 | C5 |
| 6 | 06 | 70 | 46 | 134 | 86 | 198 | C6 |
| 7 | 07 | 71 | 47 | 135 | 87 | 199 | C7 |
| 8 | 08 | 72 | 48 | 136 | 88 | 200 | C8 |
| 9 | 09 | 73 | 49 | 137 | 89 | 201 | C9 |
| 10 | 0A | 74 | 4A | 138 | 8A | 202 | CA |
| 11 | 0B | 75 | 4B | 139 | 8B | 203 | CB |
| 12 | 0C | 76 | 4C | 140 | 8C | 204 | CC |
| 13 | 0D | 77 | 4D | 141 | 8D | 205 | CD |
| 14 | 0E | 78 | 4E | 142 | 8E | 206 | CE |
| 15 | 0F | 79 | 4F | 143 | 8F | 207 | CF |
| 16 | 10 | 80 | 50 | 144 | 90 | 208 | D0 |
| 17 | 11 | 81 | 51 | 145 | 91 | 209 | D1 |
| 18 | 12 | 82 | 52 | 146 | 92 | 210 | D2 |
| 19 | 13 | 83 | 53 | 147 | 93 | 211 | D3 |
| 20 | 14 | 84 | 54 | 148 | 94 | 212 | D4 |
| 21 | 15 | 85 | 55 | 149 | 95 | 213 | D5 |
| 22 | 16 | 86 | 56 | 150 | 96 | 214 | D6 |
| 23 | 17 | 87 | 57 | 151 | 97 | 215 | D7 |
| 24 | 18 | 88 | 58 | 152 | 98 | 216 | D8 |
| 25 | 19 | 89 | 59 | 153 | 99 | 217 | D9 |
| 26 | 1A | 90 | 5A | 154 | 9A | 218 | DA |
| 27 | 1B | 91 | 5B | 155 | 9B | 219 | DB |
| 28 | 1C | 92 | 5C | 156 | 9C | 220 | DC |
| 29 | 1D | 93 | 5D | 157 | 9D | 221 | DD |
| 30 | 1E | 94 | 5E | 158 | 9E | 222 | DE |
| 31 | 1F | 95 | 5F | 159 | 9F | 223 | DF |
| 32 | 20 | 96 | 60 | 160 | A0 | 224 | E0 |
| 33 | 21 | 97 | 61 | 161 | A1 | 225 | E1 |
| 34 | 22 | 98 | 62 | 162 | A2 | 226 | E2 |
| 35 | 23 | 99 | 63 | 163 | A3 | 227 | E3 |
| 36 | 24 | 100 | 64 | 164 | A4 | 228 | E4 |
| 37 | 25 | 101 | 65 | 165 | A5 | 229 | E5 |
| 38 | 26 | 102 | 66 | 166 | A6 | 230 | E6 |
| 39 | 27 | 103 | 67 | 167 | A7 | 231 | E7 |
| 40 | 28 | 104 | 68 | 168 | A8 | 232 | E8 |
| 41 | 29 | 105 | 69 | 169 | A9 | 233 | E9 |
| 42 | 2A | 106 | 6A | 170 | AA | 234 | EA |
| 43 | 2B | 107 | 6B | 171 | AB | 235 | EB |
| 44 | 2C | 108 | 6C | 172 | AC | 236 | EC |
| 45 | 2D | 109 | 6D | 173 | AD | 237 | ED |
| 46 | 2E | 110 | 6E | 174 | AE | 238 | EE |
| 47 | 2F | 111 | 6F | 175 | AF | 239 | EF |
| 48 | 30 | 112 | 70 | 176 | B0 | 240 | F0 |
| 49 | 31 | 113 | 71 | 177 | B1 | 241 | F1 |
| 50 | 32 | 114 | 72 | 178 | B2 | 242 | F2 |
| 51 | 33 | 115 | 73 | 179 | B3 | 243 | F3 |
| 52 | 34 | 116 | 74 | 180 | B4 | 244 | F4 |
| 53 | 35 | 117 | 75 | 181 | B5 | 245 | F5 |
| 54 | 36 | 118 | 76 | 182 | B6 | 246 | F6 |
| 55 | 37 | 119 | 77 | 183 | B7 | 247 | F7 |
| 56 | 38 | 120 | 78 | 184 | B8 | 248 | F8 |
| 57 | 39 | 121 | 79 | 185 | B9 | 249 | F9 |
| 58 | 3A | 122 | 7A | 186 | BA | 250 | FA |
| 59 | 3B | 123 | 7B | 187 | BB | 251 | FB |
| 60 | 3C | 124 | 7C | 188 | BC | 252 | FC |
| 61 | 3D | 125 | 7D | 189 | BD | 253 | FD |
| 62 | 3E | 126 | 7E | 190 | BE | 254 | FE |
| 63 | 3F | 127 | 7F | 191 | BF | 255 | FF |
Column Values in Hexadecimal (Base16)
For the base16 hexadecimal number system, the 1st four
columns look like the following (note that these four columns also represent
sixteen bits or two bytes):
| Power | 163 | 162 | 161 | 160 |
| Value | 4096 | 256 | 16 | 1 |
| Column | 4th | 3rd | 2nd | 1st |
For the value of the 1st column, the base is raised to the power of zero (i.e., 160). To get the next column value, one is added to the power of the current column (i.e., 161 for the 2nd column, 162 for the 3rd column, 163 for the 4th column, etc.). Powers or exponents simply determine how many times the number should be multiplied by itself (note that the powers of zero and one are an exception).
160 = 1, any number raised to the power of zero is
1
161 = 16, any number raised to the power of one is the number
itself
162 = 16 x 16 = 256
163 = 16 x 16 x 16 =
4096
The decimal equivalent of the base16 hexadecimal number 13AC16 is:
(1x4096)+(3x256)+(10x16)+(12x1) = 5036
| 163 | 162 | 161 | 160 | = 5036 |
| 4096 | 256 | 16 | 1 | |
| 1 | 3 | A | C |
| The rightmost or 1st column indicates 12 ones. | 12 | |
| The 2nd column indicates 10 sixteens. | + | 160 |
| The 3rd column indicates 3 two-hundred-fifty-sixes. | + | 768 |
| The 4th column indicates 1 four-thousand-ninety-six. | + | 4096 |
| Adding these values together produces the decimal value | 5036 |
In any base system, the next column value to the left can be found by multiplying the current column value by the base number. This works because one is being added to the exponent for the next column. Adding one to the exponent means that the base should be multiplied by itself one more time. In the base16 hexadecimal number system, to get the column value of the next column, just multiply the current column value by 16.
| Power | 163 | 162 | 161 | 160 |
| Value | 16 x 256 = 4096 | 16 x 16 = 256 | 16 x 1 = 16 | 1 |
| Column | 4th | 3rd | 2nd | 1st |
It's easy to extend the column values of a hexadecimal number by either adding one to the power of the current column or multiplying the current column by sixteen. Here's what the column values are for a 32-bit or 4-byte hexadecimal number.
| Power | 167 | 166 | 165 | 164 | 163 | 162 | 161 | 160 |
| Value | 268,435,456 | 16,777,216 | 1,048,576 | 65,536 | 4,096 | 256 | 16 | 1 |
| Column | 8th | 7th | 6th | 5th | 4th | 3rd | 2nd | 1st |
Because the column values begin to get quite large, it makes sense to begin using a shorthand to indicate these larger values. The number 1024 can be represented by Kilo (K). The number 1024K can be represented by Meg (M). Using this shorthand makes the multiples of 1024 much easier to remember. Below is the same table using K to represent 1024 and M to represent 1024K.
| Power | 167 | 166 | 165 | 164 | 163 | 162 | 161 | 160 |
| Value | 256M | 16M | 1M | 64K | 4K | 256 | 16 | 1 |
| Column | 8th | 7th | 6th | 5th | 4th | 3rd | 2nd | 1st |
Here's what 4K and above mean:
4K = 4 x 1024 = 4,096
64K = 64 x 1024 =
65,536
1M = 1 x 1024K = 1,048,576
16M = 16 x 1024K = 16,777,216
256M =
256 x 1024K = 268,435,456
Often in computing, K is rounded to 1,000. Although this isn't quite accurate, it does make it easier to compare numbers when rough values are all that's needed. Note that many numeric shorthand letters in computing are based on the same concept as K (i.e., 1024K = 1Meg or 1M or roughly 1 million, 1024M = 1Gig or 1G or roughly 1 billion).
The decimal equivalent of the 32-bit or 4-byte base16 hexadecimal
number 1A5E7C2D16 is:
(1x256M)+(10x16M)+(5x1M)+(14x64K)+(7x4K)+(12x256)+(2x16)+(13x1) =
442,399,789
| 167 | 166 | 165 | 164 | 163 | 162 | 161 | 160 | = 442,399,789 |
| 256M | 16M | 1M | 64K | 4K | 256 | 16 | 1 | |
| 1 | A | 5 | E | 7 | C | 2 | D |
| The rightmost or 1st column indicates 13 ones. | 13 | |
| The 2nd column indicates 2 sixteens. | + | 32 |
| The 3rd column indicates 12 two-hundred-fifty-sixes. | + | 3,072 |
| The 4th column indicates 7 4K's (4,096's). | + | 28,672 |
| The 5th column indicates 14 64K's (65,536's). | + | 917,504 |
| The 6th column indicates 5 1M's (1,048,576's). | + | 5,242,880 |
| The 7th column indicates 10 16M's (16,777,216's). | + | 167,772,160 |
| The 8th column indicates 1 256M's (268,435,456). | + | 268,435,456 |
| Adding these values together produces the decimal value | 442,399,789 |
Fortunately, hexadecimal is most often used as a shorthand for binary or for addressing. In both cases, it is usually not necessary to convert from hexadecimal-to-decimal or vice versa. However, it is often necessary to convert between hexadecimal and binary.
Converting from Hexadecimal (Base16) to Binary (Base2)
Determining the binary value of a hexadecimal number simply requires converting each hexadecimal digit to four binary digits or bits. For example, the binary equivalent of the base16 hexadecimal number 1AB516 is 00011010101101012.
| Hexadecimal Digit |
Binary Digits (Bits) |
| 1 | 0001 |
| A | 1010 |
| B | 1011 |
| 5 | 0101 |
Method: Determine the decimal equivalent of each hexadecimal digit, then convert each decimal equivalent to a 4-bit binary number and combine all the binary numbers.
For example, determining the binary equivalent of the hexadecimal number 2FA016 requires that the four decimal numbers 2, 15, 10 and 0 be converted to four 4-bit binary numbers.
| Hexadecimal Value |
Decimal Value |
| 0 | 0 |
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| A | 10 |
| B | 11 |
| C | 12 |
| D | 13 |
| E | 14 |
| F | 15 |
The leftmost digit of the hexadecimal number 2FA016 is 2 in hex and also 2 in decimal. Converting 2 in decimal to a 4-bit binary number produces 00102.
| 23 | 22 | 21 | 20 | = 2 |
| 8 | 4 | 2 | 1 | |
| 0 | 0 | 1 | 0 |
The next digit of the hexadecimal number 2FA016
is F in hex which is 15 in decimal. Converting 15 in
decimal to a 4-bit binary number produces 11112.
| 23 | 22 | 21 | 20 | = 8 + 4 + 2 + 1 = 15 |
| 8 | 4 | 2 | 1 | |
| 1 | 1 | 1 | 1 |
The next digit of the hexadecimal number 2FA016 is A in hex which is 10 in decimal. Converting 10 in decimal to a 4-bit binary number produces 10102.
| 23 | 22 | 21 | 20 | = 8 + 2 = 10 |
| 8 | 4 | 2 | 1 | |
| 1 | 0 | 1 | 0 |
The last digit of the hexadecimal number 2FA016 is 0 in hex and also 0 in decimal. Converting 0 in decimal to a 4-bit binary number produces 00002.
| 23 | 22 | 21 | 20 | = 0 |
| 8 | 4 | 2 | 1 | |
| 0 | 0 | 0 | 0 |
The four 4-bit binary numbers together are 0010 1111 1010
0000.
Hexadecimal number 2FA016
= 00101111101000002 in
binary.
Converting from Binary (Base2) to Hexadecimal (Base16)
Determining the hexadecimal value of a binary number simply requires converting every four binary digits or bits to a single hexadecimal digit. For example, the hexadecimal equivalent of the base2 binary number 10010001000011102 is 910E16.
| Binary Digits (Bits) |
Hexadecimal Digit |
| 1001 | 9 |
| 0001 | 1 |
| 0000 | 0 |
| 1110 | E |
Method: Determine the decimal equivalent of every four binary digits or bits, then convert each decimal equivalent to a hexadecimal digit and combine all the hex digits.
For example, determining the hexadecimal equivalent of the binary number 1001000101101102 requires that every four bits 0100, 1000, 1011 and 0110 be converted to a hexadecimal digit. Notice that the bits must be counted from the right, then if needed, the leftmost set of bits are padded with leading zeros to create four bits for that set.
The leftmost four bits of the binary number 100 1000 1011 01102 are 0100 (note that the leading zero was added to 100 to pad out to four bits). Binary 01002 converts to decimal 4. Decimal 4 converts to hexadecimal 416.
| 23 | 22 | 21 | 20 | = 4 or 416 |
| 8 | 4 | 2 | 1 | |
| 0 | 1 | 0 | 0 |
The next four bits of the binary number 100 1000 1011 01102 are 1000. Binary 10002 converts to decimal 8. Decimal 8 converts to hexadecimal 816.
| 23 | 22 | 21 | 20 | = 8 or 816 |
| 8 | 4 | 2 | 1 | |
| 1 | 0 | 0 | 0 |
The next four bits of the binary number 100 1000 1011 01102 are 1011. Binary 10112 converts to decimal 11. Decimal 11 converts to hexadecimal B16.
| 23 | 22 | 21 | 20 | = 8 + 2 + 1 = 11 or B16 |
| 8 | 4 | 2 | 1 | |
| 1 | 0 | 1 | 1 |
The last four bits of the binary number 100 1000 1011 01102 are 0110. Binary 01102 converts to decimal 6. Decimal 6 converts to hexadecimal 616.
| 23 | 22 | 21 | 20 | = 4 + 2 = 6 or 616 |
| 8 | 4 | 2 | 1 | |
| 0 | 1 | 1 | 0 |
Combining the four hex digits gives the result 48B6.
Binary 1001000101101102 = Hexadecimal 48B616