Python Bitwise operators
Bitwise operators are used to perform operations on binary numbers. Bitwise operators with Python are as follows.
Operator | Operation |
---|---|
& | Bitwise AND |
| | Bitwise OR |
^ | Bitwise XOR |
~ | Bitwise NOT |
<< | Bitwise Zero fill LEFT SHIFT |
>> | Bitwise Zero fill RIGHT SHIFT |
Bitwise AND operator
Values are specified in decimal number system and the operation is performed on it's corresponding binary number system.
Sets each of the bit to 1, when both the bits are 1. Otherwise reset to 0.
Program
Bitwise OR operator
Sets each of the bit to 1, when one of the two bits or both the bits are 1. Reset to 0 when both are 0.
Following are the codes to perform bitwise OR operation in Python.
Program
Bitwise XOR operator
Sets each of the bit to 1, when one of the two bits are 1. If both are 1 or both are 0 it reset to 0.
Following are the codes to perform bitwise XOR operation in Python.
Program
Bitwise NOT operator
Inverts all the bits. Following are the codes to perform bitwise NOT operation in Python.
Program
Bitwise Zero fill LEFT SHIFT operator
Shifts the bit toward left by pushing the 0's to the right side and discarding leftmost bits.
The number of 0's to be pushed towards right to perform left shift is specified by us.
Program
Bitwise Zero fill RIGHT SHIFT operator
Shifts the bit toward right by pushing the 0's to the left side by discarding rightmost bits.
The number of 0's to be pushed towards left to perform right shift is specified by us.
Program
إرسال تعليق
If you have any query, feel free to ask.