1: Extension Exercise | Hexadecimal Number System
Often, hexadecimal is referred to as hex. Hexadecimal means six plus ten. This number system has a base of 16 (six plus ten). The number 10 in hexadecimal means there is one group of sixteen and no ones. In this system, there are 16 numbers between 0 and 10. This poses a problem if there are only 10 digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, __, __, __, __, __, __, 10
To accommodate this gap, the letters A, B, C, D, E, and F are used to fill in the digits between 9 and 10:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10
There is a happy coincidence between the binary system and the hexadecimal system. The first 16 binary digits can be represented as one of the hex digits, as shown in the following table.
Decimal | Binary | Hex |
---|---|---|
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | 0111 | 7 |
8 | 1000 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |
16 | 001 0000 | 10 |
This coincidence allows the writing of four binary digits in just one hex digit. Every byte of binary can be expressed using two hex digits. This saves a lot of room and makes it easier for coders to recognize the numbers.
Four bits make a nybble. Encoding characters in hex requires breaking each binary byte into two nybbles. To encode the uppercase letter A in hex, look at the binary number 0100 0001. Split it into two nybbles:
0100
0001
Look in the table and read the hex values:
0100 = 4
0001 = 1
The hex code for the character A is 41.
The greeting HELLO WORLD in binary is:
01001000 01000101 01001100 01001100 01001111 00100000 01010111 01001111 01010010 01001100 01000100
This can be compacted in hex as:
48 45 4C 4C 4F 20 57 4F 52 4C 44
The ASCII Characters table in Appendix A of this textbook includes a column for hex codes. Use the ASCII table in the appendix to encode these phrases in hex.