Python Bitwise Left Shift Operator

Left Shift Operator

Bitwise Left Shift Operator is used to push zero bits on the rightmost side and let the leftmost bits to overflow. This is also called Zero-Fill Left-Shift.

Symbol

The symbol of bitwise Left Shift operator is <<.

Syntax

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

x << y

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

Example

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

x = 5
y = 2

# Bit level
     x = 00000101
x << 2 = 00010100

Therefore x << y = 20

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

Python Program

x = 5
y = 2
output = x << y
print(f'{x}<<{y} = {output}')
Run Code Copy

Output

5<<2 = 20

Summary

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

Related Tutorials

Code copied to clipboard successfully 👍