I am confused as to when I should use Boolean vs bitwise operators
and vs &or vs |
Boolean operation are logical operations.
Bitwise operations are operations on binary bits.
Bitwise operations:
>>> k = 1
>>> z = 3
>>> k & z
1
>>> k | z
3
The operations:
&: 1 if both bits are 1, otherwise 0|: 1 if either bit is 1, otherwise 0^: 1 if the bits are different, 0 if they're the same~': Flip each bitSome of the uses of bitwise operations:
Boolean operations:
>>> k = True
>>> z = False
>>> k & z # and
False
>>> k | z # or
True
>>>