## Update, solved! (I hope it's correct ) I won't delete it, maybe it helps someone.

def check_bit4(i):

i = int(i)

mask=0b1000

desired = int(bin(i),2)&int(bin(mask),2)

if desired > 0:

return "on"

else:

return "off"

Hi all,

I am struggling with this example and have already found a solution, that results with "correct" but I'm pretty sure it's incorrect.

def check_bit4(i):

i=int(i)

mask=0b1000

desired = i&mask #I think most of already posted codes compare 16&0b1000 instead of 0b1000

if desired > 0:

return "on"

else:

return "off"

for check_bit4(16) it comes up with off

I have also tried out several other solutions,

for example

def check_bit4(i):

i=int(i,2) # or int(str(i),2)

mask=0b1000

desired = i&mask

if desired > 0:

return "on"

else:

return "off"

I've also tried bit(i), but the global variablebit is not defined

could someone give me a hint? thanks in advance!