Binary is an effective number system for computers because it is
easy to implement with digital electronics. It is inefficient for
humans to use binary, however, because it requires so many digits to
represent a number. The number 76, for example, takes only two digits
to write in decimal, yet takes seven digits to write in binary
(1001100). To overcome this limitation, the hexadecimal number system was developed. Hexadecimal is more compact than binary but is still based on the digital nature of computers.
Hexadecimal works in the same way as binary and decimal, but it uses
sixteen digits instead of two or ten. Since the western alphabet
contains only ten digits, hexadecimal uses the letters A-F to represent
the digits ten through fifteen. Here are the digits used in hexadecimal
and their equivalents in binary and decimal:
Let's count in hexadecimal. Starting from zero, we count 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, A, B, C, D, E, F. At this point there are no more
digits, so we add another column. Continue counting: 10, 11, 12, 13,
14, 15, 16, 17 18, 19, 1A, 1B, 1C, 1D, 1E, 1F. Once again, we are out
of digits in the first column, so we add one to the next column.
Continue counting once again: 20, 21, 22, ..., 29, 2A, 2B, 2D, 2E, 2F,
30, 31, 32, ..., 3E, 3F, 40, 41, 42, ... 99, 9A, 9B, 9C, 9D, 9E, 9F,
A0, A1, A2, ... F9, FA, FB, FC, FD, FE, FF, 100, 101, 102, .... Watch
the pattern of numbers and try to relate this to the way you count in
decimal or binary. You will see that it is the same procedure, but with
sixteen digits instead of 10 or 2.
Each column in hexadecimal is worth 16 times the column before,
while each column in binary is worth 2 times the column before. Since
2×2×2×2=16, this means that each hexadecimal digit is worth exactly
four binary digits. This fact makes it easy to convert between binary
and hexadecimal.
To convert from hexadecimal to binary, simply look at the chart
above and replace each digit in the hexadecimal number with its
corresponding four-digit binary number. For example, 8F in hexadecimal
is 10001111 in binary, since 8=1000 and F=1111.
To convert from binary to hexadecimal, reverse the procedure and
break the binary number into blocks of four digits. Then, replace each
block of four digits with its corresponding hexadecimal digit. If you
cannot divide the binary number evenly into blocks of four digits, add
zeros to the left side of the number to make it work. For example, to
convert 110101 to hexadecimal, first add two zeros at the beginning of
the number to make it 00110101. Since 00110101 has eight digits, it can
be divided into two blocks of four digits, 0011 and 0101. Since 0011=3
and 0101=5, the corresponding hexadecimal number is 35.