Python Bitwise Right Shift Operator

Right Shift Operator

Bitwise Right Shift Operator is used to copy the sign bit and push it on the leftmost side and let the rightmost bits to overflow. This is also called Signed Right-Shift.

Symbol

The symbol of bitwise Right Shift operator is >>.

Syntax

The syntax to do bitwise Right Shift operation for the operands: x and y, is

x >> y

This operation right shifts the bits in x, by y number of times.

Example

The following is a simple example of how bitwise Right Shift operation is done for given two numbers.

x = 5
y = 2

# Bit level
     x = 00101001
x >> 2 = 00001010

Therefore x >> y = 10

In this following program, we take integer values in x, and y, and perform bitwise Right Shift operation x >> y.

Python Program

x = 41
y = 2
output = x >> y
print(f'{x}>>{y} = {output}')
Run Code Copy

Output

41>>2 = 10

Summary

In this tutorial of Python Examples, we learned about Bitwise Right Shift Operator, and it’s usage with the help of examples.

Code copied to clipboard successfully 👍