The Man Behind the Bit Mask


Please help me on this. It is throwing error


def check_bit4(input):
inputBinary = bin(input)
length = len(inputBinary)
if(input >=8 and inputBinary[length-4]>0):
return 'on'
return 'off'


Hi my friend, you're almost there only change the "+" to "&" and you have the answer. Thanks, happy coding.


how can we use 'input' as an argument here? are we allowed to use predefined python variables as arguments??


It is not a good practice, from a readability standpoint, but the variable is locally defined so does not clash with the built-in function (afaik). Had it been defined globally, it would have replaced the function in the namespace requiring a restart of the shell to restore it.


4 posts were split to a new topic: Unable to understand the mistake - Bit Mask