Shift Operators in C Language
This “Shift Operators in C Language” post is providing complete information about all the shift operators which are available in C language with suitable examples.
The bit wise shift operators move the bit values in the memory location .
The left operand specifies the value to be shifted.
The right operand specifies the number of positions that the bits in the value are to be shifted.
The bit shift operators take two arguments, and looks like:
x << n
x >> n
Where x can be any kind of int variable or char variable and n can be any kind of int variable.
short int a=8,b,c;
b = a << 2 ;
c = a >> 2 ;
Note : shift operators having higher prior than relational operators.
c = a << 2 == 8 ;
d = b >> 2 == 2 ;
Theoretical formulas to shift data bits :
>> –> n/2^s (n divided by 2 power s)
<< –> n*2^s (n multiplied by 2 power s)
where “n” represents data
“s” represents bits to be shifted