1
Bitwise operators work directly with binary formats and bits at a lower level.
2
There are six bitwise operators in Python: complement (~), AND (&), OR (|), XOR (^), left shift (<<), and right shift (>>).
3
Complement operator (~): Reverses binary digits (0 becomes 1, 1 becomes 0). Systems use 2's complement (1's complement + 1) to represent negative numbers, which explains why ~12 results in -13.
4
Bitwise AND (&): Returns 1 only if both bits are 1.
5
Bitwise OR (|): Returns 1 if at least one of the bits is 1.
6
XOR (^): Returns 1 if the bits are different (odd number of 1s), and 0 if they are the same.
7
Left shift (<<): Shifts bits to the left by a specified number of positions, effectively multiplying the number by powers of 2 (e.g., 10 << 2 yields 40).
8
Right shift (>>): Shifts bits to the right by a specified number of positions, discarding bits and effectively dividing the number (e.g., 10 >> 2 yields 2).