[10pts] Fill in the blank in the code so that the output is correct. Note:
do not use any string operation, any loop, or any if statement. Use bit
operations.
#===========================================================================
# fill in the blank: Write a function get_at
# input
# - n: an 8-bit integer
# - i: an integer between 0 and 7 (inclusive)
# output
# the i-th bit of n (as an integer)
# WARNING:
# - You are only allowed to use the following operations:
# bitwise-and, bitwise-or, bitwise-xor, shift-left,
# shift-right, parenthesis, addition, subtraction.
# All the other operations (e.g., multiplication, string, list, etc.)
# are prohibited.
#
# - The function should work correctly for any 8-bit integer n.
def get_at(n, i):
return _________________________________________________
Here are sample runs.
Carefully inspect the sample run to see how the indexing of i works
>>> for i in range(8):
... print( get_at(0b11101100, i) )
...
1
1
1
0
1
1
0
0
|
|
>>> print( get_at(0b00110011, 0) )
0
>>> print( get_at(0b00110011, 1) )
0
>>> print( get_at(0b00110011, 2) )
1
>>> print( get_at(0b00110011, 6) )
1
>>> print( get_at(0b00110011, 7) )
1
|