CS255 Syllabus
• Hexademical number system: number system based on number 16

• Has 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
• Value of digits increase by 16 for each position
```   Example:

BAD(16) = 11 x 162 + 10 x 161 + 13 x 80
= 2816 + 160 + 13 = 298910
```

• Finding the representation of a value in the hexadecimal number system:

• Divide the value repeated by 16
• Collect the remainders in the reverse order

(The procedure is exactly the same as the one to find the representation for a value in the binary number system, except you need to divide by 8 instead of 2)

``` Example:

value = 30

Find the representation in the octal number system:

30
16 ------ 14  (= E)
1
16 ------ 1
0

representation is ----> 1E(16)
```
• Hexadecimal numbers are also mainly used to show binary code because hexadecimal number can be converted easily to binary numbers and vice versa.

• Converting hexadecimal numbers to binary numbers:

• Convert each octal digit to 4 binary digits using:
```      Hex digit         Binary digits
-----------       -------------
0      -->        0000
1      -->        0001
2      -->        0010
3      -->        0011
4      -->        0100
5      -->        0101
6      -->        0110
7      -->        0111
8      -->        1000
9      -->        1001
A      -->        1010
B      -->        1011
C      -->        1100
D      -->        1101
E      -->        1110
F      -->        1111

Example:

901(16) = 100100000001
```

• Converting binary numbers to hexadecimal numbers:

• Convert (starting from the right) each group of 4 binary digits into one hexadecimal digit using:
```      Binary digits      Hex digit
-------------     -----------
0000       -->      0
0001       -->      1
0010       -->      2
0011       -->      3
0100       -->      4
0101       -->      5
0110       -->      6
0111       -->      7
1000       -->      8
1001       -->      9
1010       -->      A
1011       -->      B
1100       -->      C
1101       -->      D
1110       -->      E
1111       -->      F

Example:

11010101 = D5(16)
10010001 = 91(16) (Note: this is NOT equal to 91 decimal !)
```

• NOTE: we prefer to use hexadecimal number to represent binary numbers because 2 hexadecimal digits is equal to 1 byte !