Bitwise operator:
- x=x<<2 means new value of x is shifted left by 2 positions
- y=y>>3 means new value of y is shifted right by 3 positions
#include<stdio.h>
void main()
{
int x,y;
x=128;
printf(" After right- shifting by 1, x=%d/n" ,x);
y=y<<2;
printf(" After left- shifting by 2, y=%d/n" ,y);
} // End of main() //
Output:
/* Binary value of x before shifting :
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Binary value of x after shifting right by 1 :
0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
After right-shifting by 1, x=64 // 64 is equivalent to 01000000 binary number //
/* Binary value of y before shifting :
1 | 0 | 0 | 0 | 0 | 0 |
Binary value of y after shifting right by 2 :
0 | 0 | 1 | 0 | 0 | 0 |
After left-shifting by 2, y=128 // 128 is equivalent to 001000 binary number //
0 Response to "Explanation of Bitwise C Operator with Examples"
Post a Comment