Skip to main content

Python Bitwise Operators

Satellite · Operators

Python Bitwise Operators

Bitwise operators unlock low-level tasks like masking, permissions, and performance-sensitive math.

Operations

OperatorMeaningExample
&ANDflags & 0b0101
``OR
^XORa ^ b
~NOT~value (bitwise complement)
<<Left shiftvalue << 1 multiplies by 2
>>Right shiftvalue >> 1 floor-divides by 2

Examples

READ = 0b001
WRITE = 0b010
EXECUTE = 0b100

permissions = READ | WRITE
has_write = bool(permissions & WRITE)

Use bitmasks for feature flags, permissions, or compact storage.

Next up in your learning path