Introduction
Operators in programming languages are special symbols or phrases that tell the compiler or interpreter to perform specific mathematical, relational, or logical operations and return a result. They are similar to verbs in the English language. Just as verbs express action or a state of being—like "run," "is," or "have"—operators in a programming language trigger actions on data. Among these operators, the shift operators in C allow you to shift bits left or right within an integer value. These operators provide a quick way to multiply or divide numbers by powers of two.

In this article, we will discuss the left shift (<<) & right shift (>>) operators in C, their syntax, examples, and applications.
Left Shift (<<) Operator
The left shift operator (<<) in C shifts the bits of a number to the left by a specified number of positions. When you left shift a number, the bits are moved to the left, and the rightmost bits are filled with zeros. Each left shift essentially doubles the number, which is equivalent to multiplying the number by 2 raised to the power of the number of positions shifted.
Syntax
The syntax for the left shift operator in C is :
number << positions
Here, "number" represents the integer value you want to shift, and "positions" specifies the number of positions to shift the bits to the left.
Example of Left Shift Operator
Let's take a look at an example to understand how the left shift operator works in C:
#include <stdio.h>
int main() {
int num = 5;
int shifted = num << 2;
printf("Original number: %d\n", num);
printf("Shifted number: %d\n", shifted);
return 0;
}
Output:
Original number: 5
Shifted number: 20
In this example, we have an integer variable `num` with a value of 5. We apply the left shift operator (`<<`) to `num` and shift it by 2 positions. The result is stored in the `shifted` variable.
The binary representation of 5 is `0101`. When we left shift it by 2 positions, it becomes `010100`, which is equivalent to the decimal value 20.
Therefore, left shifting 5 by 2 positions is equivalent to multiplying 5 by 2^2 (2 raised to the power of 2), which equals 20.
Applications of Left Shift Operator
The left shift operator has several applications in C language like:
1. Multiplying by powers of 2: Left shifting a number by `n` positions is equivalent to multiplying it by 2^n. This can be a faster alternative to multiplication when the multiplier is a power of 2.
2. Bitwise manipulation: Left shift is often used in low-level programming & embedded systems to manipulate individual bits of a number. It can be used to set, clear, or toggle specific bits.
3. Packing data: Left shift can be used to pack multiple smaller values into a single larger value. For example, you can use left shift to combine two 16-bit integers into a single 32-bit integer.
4. Encryption & compression: Left shift is sometimes used in encryption algorithms & data compression techniques to rearrange or transform data.