C Bitwise Left Shift : (<<) Operator

Bitwise Left Shift Operator in C

  1. It is denoted by <<
  2. Bit Pattern of the data can be shifted by specified number of Positions to Left
  3. When Data is Shifted Left , trailing zero’s are filled with zero.
  4. Left shift Operator is Binary Operator [Bi - two]
  5. Binary means , Operator that require two arguments

Quick Overview of Left Shift Operator

Original Number A 0000 0000 0011 1100
Left Shift 0000 0000 1111 0000
Trailing Zero’s Replaced by 0
(Shown in RED)
Direction of Movement of Data <<<<<=======Left

Syntax : Bitwise Left Shift Operator

[variable]<<[number of places]

Live Example : Bitwise Operator [Left Shift Operator]

#include<stdio.h>
int main()
{
int a = 60;
printf("\nNumber is Shifted By 1 Bit : %d",a << 1);
printf("\nNumber is Shifted By 2 Bits : %d",a << 2);
printf("\nNumber is Shifted By 3 Bits : %d",a << 3);
return(0);
}

Output :

Number is Shifted By 1 Bit  : 120
Number is Shifted By 2 Bits : 240
Number is Shifted By 3 Bits : 480

Explanation of Left Shift Binary Operator :

We know the binary representation of the 60 is as below -

0000 0000 0011 1100

Now after shifting all the bits to left towards MSB we will get following bit pattern -

0000 0000 0011 1100   = 60
<< 1
-------------------
0000 0000 0111 1000   = 120

Observations and Conclusion :

Shfting Binary 1 to Left By ‘X’ Bits Decimal Value Converted Value
0 Bit 2^0 1
1 Bit 2^1 2
2 Bits 2^2 4
3 Bits 2^3 8
4 Bits 2^4 16
5 Bits 2^5 32
6 Bits 2^6 64
7 Bits 2^7 128
8 Bits 2^8 256