Does Python Have Bitwise Operators A Complete Guide

Logan Jul 13, 2026

When exploring Python's versatile suite of operators, a common query is: "Does Python have bitwise operators?" The answer is a resounding yes! Python provides a rich set of bitwise operators, much like C, C++, Java, and other low-level languages, enabling bit-level manipulation of integers.

Python Bitwise Operators - A proper guide with syntax and examples
Python Bitwise Operators - A proper guide with syntax and examples

Understanding bitwise operators is crucial for tasks like memory management, algorithm optimizations, and hardware-related programming. In Python, these operators are designed to operate on numbers treated as binary sequences. Let's delve into the world of Python's bitwise operators.

Python bitwise operators cheat sheet
Python bitwise operators cheat sheet

Bitwise Operators in Python

Python offers eight bitwise operators, each serving a unique purpose in binary manipulation. To understand how they work, let's first recall that an integer like 10 in decimal is represented as 1010 in binary.

PYTHON OPERATORS
PYTHON OPERATORS

Here's a brief overview of these operators, which we'll explore in more detail later:

  • & (Bitwise AND): Returns 1 if both bits are 1, else 0.
  • | (Bitwise OR): Returns 1 if any of the bits is 1, else 0.
  • ^ (Bitwise XOR): Returns 1 if the bits are different, else 0.
  • ~ (Bitwise NOT): Inverts all bits e.g., changes 1s to 0s and vice versa.
  • << (Left Shift): Shifts the bits of the number to the left e.g., 10 >> 2 becomes 25.
  • >> (Right Shift): Shifts the bits of the number to the right e.g., 10 >> 2 becomes 2.
Python Operators Explained for Beginners
Python Operators Explained for Beginners

Bitwise AND (&)

Bitwise AND performs a logical AND on every bit of the operands, resulting in a 1 only if both bits are 1. For instance, 10 (1010) & 7 (0111) equals 2 (0010). The truth table for this operator is:

donnée1 donnée2 Résultat
0 0 0
0 1 0
1 0 0
1 1 1
Python bitwise operators cheat-sheet
Python bitwise operators cheat-sheet

Bitwise OR (|)

Bitwise OR performs a logical OR on every bit of the operands, resulting in a 1 if any of the bits is 1. For example, 10 (1010) | 7 (0111) equals 15 (1111). The truth table is:

donnée1 donnée2 Résultat
0 0 0
0 1 1
1 0 1
1 1 1
Bitwise Operators in Python
Bitwise Operators in Python

Bitwise XOR (^)

Bitwise XOR performs a logical XOR on every bit of the operands, resulting in a 1 if the bits are different. For instance, 10 (1010) ^ 7 (0111) equals 13 (1101). The truth table is:

4 most important Bitwise operator that  every programmer should know
4 most important Bitwise operator that every programmer should know
Python Operators Tutorial – Chapter 3 Notes
Python Operators Tutorial – Chapter 3 Notes
Operators in Python
Operators in Python
Mastering Bitwise Operators in Python: A Complete Guide
Mastering Bitwise Operators in Python: A Complete Guide
Bitwise Operators in Python – Real Python
Bitwise Operators in Python – Real Python
All Important Python Functions for Beginners (Complete Cheat Sheet)
All Important Python Functions for Beginners (Complete Cheat Sheet)
Math Operators in Python
Math Operators in Python
Python Operators Explained 🐍
Python Operators Explained 🐍
Coding For Beginners Python - Learn the Basics - Operators
Coding For Beginners Python - Learn the Basics - Operators
Python Operators 😎✨
Python Operators 😎✨
Python Cheat Sheet for Beginners 2026 | Python Basics, Syntax, Loops, Functions & Variables
Python Cheat Sheet for Beginners 2026 | Python Basics, Syntax, Loops, Functions & Variables
Python operators infographic with cartoon elements
Python operators infographic with cartoon elements
Python Operators: The Complete Guide for Beginners
Python Operators: The Complete Guide for Beginners
Understanding bitwise operators in Python
Understanding bitwise operators in Python
Python operators cheat sheet infographic
Python operators cheat sheet infographic
a diagram with the words python operators on it
a diagram with the words python operators on it
🐍🦎
🐍🦎
Python Cheat Sheet for Beginners
Python Cheat Sheet for Beginners
Python - Basic Operators: Types of Operator
Python - Basic Operators: Types of Operator
Coding For Beginners Python - Learn the Basics - Operators
Coding For Beginners Python - Learn the Basics - Operators
donnée1 donnée2 Résultat
0 0 0
0 1 1
1 0 1
1 1 0

Advanced Bitwise Operations

The remaining bitwise operators — Left Shift (<<), Right Shift (>>), and Bitwise NOT (~)—also behave as expected from other low-level languages. They respectively shift bits to the left and right, and invert all bits.

Bitwise Left Shift (<<)

Bitwise left shift multiplies the given number by 2 raised to the power of the shift number. For example, 10 << 2 (1010 << 2) equals 40 (101000), as 10 * 2^2 equals 40. It essentially "doubles" the number by pushing its digits to the left.

Bitwise Right Shift (>>)

Bitwise right shift divides the given number by 2 raised to the power of the shift number. It "halves" the number by pushing its digits to the right. For instance, 10 >> 2 (1010 >> 2) equals 2 (0010), as 10 / 2^2 equals 2.5, which rounds down to 2 as Python truncates decimals during integer division.

Understanding Python's bitwise operators enriches your problem-solving toolbox, enabling more efficient algorithms and allowing you to tackle highly optimized, low-level programming tasks!