Account
Categories

LEFT SHIFT Operator (<<)


Definition:

It is a bitwise operator, called the Left Shift operator.

It works on the binary representation of a number.

It shifts all bits of a number (operand) to the left by a given number of positions.

The empty positions on the right side are filled with 0.

Each left shift multiplies the number by 2.

Now you will clearly understand this with the help of the diagram.

a = 6   → 0110

Shift Left by 1

        0110
          ↓
        1100

Result = 12

Syntax:

result = operand << n

Example:

a = 6   # binary: 0110

result = a << 1

print(result)

Output:

Explanation:

0110 (6)

shift left by 1 → 1100

= 12

Exercise

Use Left Shift operator with value 5 and shift it by 1 position using Python.