Man behind the bit Mask


#1



def check_bit4(input):
mask = 0b1000
desired = input & mask
if desired = 1:
return "on"
else:
return "off"

print check_bit4(0b1) # ==> "off"
print check_bit4(0b11011) # ==> "on"
print check_bit4(0b1010) # ==> "on"


File "python", line 4
if desired = 1:
^
SyntaxError: invalid syntax


if desired >0 is not and desired = 1 is syntax error 


Replace this line with your code. 



#2

so close!

don't assign the value 1 to desire but check if desired > 0: Because that would be checking if the fourth bit is on.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.