I have completed the code on the below exercise and received a 'Way to go!' correct message:
I decided to test it out to make sure I understood it and one of my examples returned "off" in the console even though the fourth bit from the right was 1. Is anyone able to explain this? Does the binary string have to be of equal length to the 'mask' and if so why?
Here is my entire code with the example:
mask = 0b1000
desired = input & mask
if desired > 0:
Obviously, all of the bits are '1' but this still returned as "off".
Actually this is even the case for:
It returns "off" so seems not related to string length.
print check_bit4(1010), returns "off" too but print check_bit4(1000) returns "on"
Confused! Any help appreciated!