C program to shift inputed data by two bits to the left

Left shift operator shifts all bits towards left by certain number of specified bits. It is denoted by <<.

Example: Given Number is 2.
convert 2 into binary
i.e 0010 2 —>0010
Shift 2 bits towards left —->1000 (append zero’s to trailing end)
After 2 bit left shift, 1000—->16

				
					#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
int x,y; 
clrscr(); 
printf(“Read the integer from keyboard :”); 
scanf(“%d”,&x); 
x<<=3; 
y=x; 
printf(“\nThe left shifted data is = %d ”,y);
getch(); 
}
				
			
Output: 
Read the integer from keyboard : 2
The left shifted data is = 16

Leave a Reply