Definition:
It is a bitwise operator, called the Right Shift operator.
It works on the binary representation of a number.
It shifts all bits of a number (operand) to the right by a given number of positions.
The empty positions on the left side are filled with 0 (for positive numbers).
Each right shift divides the number by 2.
Now you will clearly understand this with the help of the diagram.
a = 12 → 1100
Shift Right by 1
1100
↓
0110
Result = 6
Syntax:
result = operand >> n
Example:
a = 12 # binary: 1100
result = a >> 1
print(result)
Output:
Explanation:
1100 (12) shift right by 1 → 0110 = 6
Exercise
Use Right Shift operator with value 16 and shift it by 2 positions using Python.
