Bitwise Operators


#1

I’m at the bitwise operators lessons now but I have a simple question:

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

What does the parameter input do? It doesn’t have any arguments passed to it as far as I’m aware. So how can it compare with the variable mask ?
(This is my whole code)


#2

we can pass arguments at function call to the parameter, until the function is called the function isn’t executed, so the parameter (input) just acts as placeholder


#3

Yes but the function isn’t called anywhere :smiley: … But the code still returns “on” or “off” … how ?

Edit: typo’s


#4

well, the exercise needs to validate the code, the easiest way to do so is to call the function and compare the returned result. This might cause output in the lesson. Go run on repl.it for example, there will be no output


#5

Ok yeah it makes sense … I always get confused with parameters.