okay a hexadecimal code is a four bit binary number. All binary numbers are powers of 2.
8 4 2 1 // this is a four bot binary table D is equal to 13
11 0 1 is the binary of D
0 0 0 1 is the binary of 1
now expand this to a full eight bit table and simply add the value of the columns with a one in them.
128 64 32 16 8 4 2 1
1 1 0 1 0 0 0 1 = 128+64+17 = 209
D1 is decimal 209
59 will now be broken down as above
128 64 32 16 8 4 2 1
0 0 1 1 1 0 1 1 is the full eight bit representation
8 4 2 1
0 0 1 1 = 3 // first hex digit
1 0 1 1 = B second hex digit
Now you try two so I can see if you understand
decimal 171
and E6 hexadecimal