Python
Bitwise Operators in Python
Bitwise Operators
76
#description
Bitwise operators are used to perform operations on bits of binary numbers. These operators are used in code to manipulate data at the bit level.
Here are the bitwise operators in Python:
- AND (&): Performs the AND operation on two bits. It returns 1 only if both bits are 1, otherwise, it returns 0.
- OR (|): Performs the OR operation on two bits. It returns 1 if either of the bits is 1, otherwise, it returns 0.
- XOR (^): Performs the XOR (exclusive OR) operation on two bits, which returns 1 if only one of the bits is 1, otherwise, it returns 0.
- NOT (~): Flips the bits (inverts the bits). It returns 0 if the corresponding bit is 1, and vice versa.
- Left Shift (<<): Shifts the bits left by the specified number of places. The leftmost bits are filled with 0.
- Right Shift (>>): Shifts the bits right by the specified number of places. The rightmost bits are filled with 0.
These operators are commonly used in cryptography, network programming, and other areas where data is represented in binary form.
March 25, 2023