Python – Shift Operators

Shift operators:

  • These are used to move the bits in the memory either to right side or to left side.
  • Moving binary bits in the memory change the value of variable.
  • These operators return the result in decimal format only.
  • Operators are Right shift (>>) and Left shift (<<)
>>> x=8
>>> x>>2
2
>>> x<<2
32

Right shift: n/2^s à 8/2^2 à 8/4 à 2

Left shift : n*2^s à 8*2^2 à 8*4 à 32

Scroll to Top