I am confused as to when I should use Boolean vs bitwise operators
and
vs &
or
vs |
are usually used for conditional statements. For example:
if a==2 and b>10:
# Do something ...
It means if both conditions (a==2
and b>10
) are true at the same time then the conditional statement body can be executed.
are used for data manipulation and extraction. For example, if you want to extract the four LSB (Least Significant Bits) of an integer, you can do this:
p & 0xF