bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Python/Foundations
Python•Foundations

Python Bitwise Operators

Bitwise Operators

Bitwise operators are used to compare (binary) numbers:

OperatorNameDescriptionExample
&ANDSets each bit to 1 if both bits are 1x & y
ORSets each bit to 1 if one of two bits is 1xy
^XORSets each bit to 1 if only one of two bits is 1x ^ y
~NOTInverts all the bits~x
<<Zero fill left shiftShift left by pushing zeros in from the right and let the leftmost bits fall offx << 2
>>Signed right shiftShift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall offx >> 2

Previous

Python Membership Operators

Next

Python Operator Precedence