Write a program to shift inputted data by two bits right.

#include<stdio.h>
#include<conio.h>
int main()
{
	int x,y;
	printf("Red the integer from keyboad (x) :-");
	scanf("%d",&x);
	x>>=2;           // >> Right shift operator //
	y=x;
	printf("The right shifted data is =%d",y);
}

/*The number enterd through the keyboard is 8 and its corresponding binary number is 1000.
Shifting two bits right means the inputted number is to be divided by 2^s where s is the no shifts 
In short:-
Y=N/2^S,where n=number & s=the no of position to be shift
above program Y=8/2^2=2*/

The program takes an integer input from the user, then uses the right shift operator (>>) to shift the value of the inputted integer by two bits to the right. The result is stored in the integer variable y. Finally, the shifted value is printed on the screen.

The right shift operator shifts the bits of the binary representation of the number to the right by the specified number of positions. In this case, it is shifting the bits two positions to the right, which is equivalent to dividing the number by 2^2 (2 raised to the power of 2).

So, if the input number was 8 (binary 1000), after shifting two bits to the right, the binary representation would become 0010, which is equal to 2 in decimal. Hence, the value of y will be 2, which is printed on the screen.

Thanks

Write a program to shift inputted data by two bits right.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top