11/14 Bit_Check function input variable type, integer or string?


#1

In the function below, the variable type of "input" is integer. The function performs an operation on "input," which is an integer, and "mask," which is a... what? Is it a string, unicode, or binary? If "mask" is not an integer, how does Python know to convert "input" to a different variable type? Is it because "mask" is binary or because & is a binary operator?

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

#2

bin(i) is a String
a = 0b111 will be an integer.

to know, simply ask python !

a = 0b1000
b = bin(2)
print type(a), type(b)

Python doesn't convert the input.
The operators (&, | ,^) themselves are designed for INTEGER input.
using strings will give an error.

Hope your doubt is cleared.


#3

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