11. The man behind the mask :( it still considers input as string :/



11.the man behind the mask exercise in bit wise operations in python

Oops, try again. Does your check_bit4 function take exactly one argument (an integer)? Your code threw a "unsupported operand type(s) for &: 'str' and 'int'" error.

I expected it to work .. I First get input then transfer it to integer then to a binary number and compared it with & operator to the mask .. why did it still considering input as a string ?????

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


Because bin returns a string -> https://docs.python.org/2/library/functions.html#bin

Binary number is just a number, take a look:

x = 0b1000
print x
=> 8

You don't have to modify input in any way.


Aha :smiley: thanks a lot @factoradic


You're very welcome! :slight_smile:


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