Bitwise Operations

Peter Otten __peter__ at web.de
Tue Jul 30 01:06:44 EDT 2013


Devyn Collier Johnson wrote:

> On Python3, how can I perform bitwise operations? For instance, I want
> something that will 'and', 'or', and 'xor' a binary integer.

>>> 0b1010 | 0b1100
14
>>> bin(_)
'0b1110'
>>> 0b1010 & 0b1100
8
>>> bin(_)
'0b1000'
>>> 0b1010 ^ 0b1100
6
>>> bin(_)
'0b110'





More information about the Python-list mailing list