Logo

Developer learning path

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:

  1. AND (&): Performs the AND operation on two bits. It returns 1 only if both bits are 1, otherwise, it returns 0.
  1. OR (|): Performs the OR operation on two bits. It returns 1 if either of the bits is 1, otherwise, it returns 0.
  1. 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.
  1. NOT (~): Flips the bits (inverts the bits). It returns 0 if the corresponding bit is 1, and vice versa.
  1. Left Shift (<<): Shifts the bits left by the specified number of places. The leftmost bits are filled with 0.
  1. 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

If you don't quite understand a paragraph in the lecture, just click on it and you can ask questions about it.

If you don't understand the whole question, click on the buttons below to get a new version of the explanation, practical examples, or to critique the question itself.