11. The Man Behind the Bit Mask



Oops, try again. Your function fails on check_bit4(0b0). It returns "on" when it should return "off".

I don't know what's wrong.

def check_bit4(input):
    mask = 0b01000
    if mask > 0:
        return "on"
        return "off"


Instruction says---

A bit mask can help you turn specific bits on, turn others off, or just collect data from an integer about which bits are on or off.

Here we have to check 4th bit.
so we need 4 - bit bitmask value--
mask = 0b1000

Now how to mask using & operator?
You have and (&) operator,the number and mask number right?


I hope it helps! :slight_smile:
do reply if it solved the problem or not!


Thank you soo much!!! It has solved my problem :grin:

def check_bit4(input):
    mask = 0b1000
    need = input & mask
    if need > 0 :
        return "on"
        return "off"


Great!!!! :slight_smile:
Keep up the good work :thumbsup:


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