Shashank Verma Shashank Verma - 11 months ago 47
Python Question

How to do & operation on binary no.(0b1100) and bin(4)?

I am finding difficulty performing a bitwise & operation between the

in binary form. How can I achieve this goal?


If you are trying to perform the bitwise AND operation (using the & operator) on two integers, there is no need to convert them to strings of their binary representations.

Take this example:

x = 4 # 0b100
y = 5 # 0b101
print(x & y) # => 4, which is 0b100, because 0b100 & 0b101 = 0b100