Looking for python Answers? Try Ask4KnowledgeBase
Looking for python Keywords? Try Ask4Keywords

Python Language Bitwise Right Shift


Example

The >> operator will perform a bitwise "right shift," where the left operand's value is moved right by the number of bits given by the right operand.

# 8 = 0b1000
8 >> 2
# Out: 2
# 2 = 0b10

bin(8 >> 2)
# Out: 0b10

Performing a right bit shift of 1 is equivalent to integer division by 2:

36 >> 1
# Out: 18

15 >> 1
# Out: 7

Performing a right bit shift of n is equivalent to integer division by 2**n:

48 >> 4
# Out: 3

59 >> 3
# Out: 7