The Man Behind the Bit Mask


#1

Please help me on this. It is throwing error


#2

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


#3

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


#5

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


#6

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.


#8

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


#9