0

I am doing some and, or operations in python and I am getting a very different result. I am not able to understand the logic behind this.

input -> 22 & 1
output-> 0
input -> 22 & 21 
output-> 20
input -> 34 | 30
output ->62
input -> 2 | 9
output -> 11

Please assist me in understanding the logic Screenshot attached

Community
  • 1
  • 1
subhanshu kumar
  • 372
  • 3
  • 10
  • As the name suggest, the operators are *bit-wise*. Use `bin` for each number to see their binary representation to aid your reasoning. For example, see `bin(22)` and `bin(1)` and convince yourself that there's no two bits that would be 1 in the same position for the two numbers. – gstukelj Oct 30 '19 at 11:37
  • That is pure teoretical question read all about it [Bitwise Operators] (https://wiki.python.org/moin/BitwiseOperators) – Mouse on the Keys Oct 30 '19 at 11:40

0 Answers0