Since homework 6 will not be collected and graded, it might be helpful to have a solution to study. Please first try to solve the problem on your own.
We have a binary value: 11111110111011011111101011001110
To express this in octal, first break it into groups of 3 bits, starting the grouping from the Least Significant Bit (the rightmost bit):
11 111 110 111 011 011 111 101 011 001 110 3 7 6 7 3 3 7 5 3 1 6
To express this in hexadecimal, break it into groups of 4 bits, starting the grouping from the Least Significant Bit:
1111 1110 1110 1101 1111 1010 1100 1110 F E E D F A C E
The least significant bit of the "direction" is at bit 6 of gps. In
the result, this must be bit 0. So we can begin by shifting to the
right 6 places:
(gps >> 6)
However, only bits 0—5 of this are the direction; there may be bits
to the left of bit 5 that are other "fields" in gps. So we need to
create a mask that will only keep the right-most 6 bits:
0011 1111 3 F
So our final result is:
dir = (gps >> 6) & 0x3F;