Friday 4 December 2015

Bitwise Operators in python


Python supports following bitwise operators, to perform bit wise operations on integers.

Operator
Description
>> 
bitwise right shift
<< 
bitwise left shift
&
bitwise and
^
Bitwise Ex-OR
|
Bitwise or
~
Bitwise not

Following post, explains bitwise operators clearly.


>>> a=2
>>> a>>1
1
>>> 
>>> a<<1
4
>>> 
>>> a&3
2
>>> a|3
3
>>> 
>>> ~a
-3



Previous                                                 Next                                                 Home

No comments:

Post a Comment