How to use shift operators
Right and Left shift operators
The right and left shift operators are binary operators.One operand represents the number in which bits are to be shifted and the other operand represents the shift positions.The shift operators are applied on integer data type variables.
Right shift operator
The right shift operator shifts all the bits of a binary number in the right direction.
Binary representation of 6 in bits.
The operator shifts the bits of this binary number to right by 2 positions,the two rightmost bits are discarded.
0000 0001 6>>2=1
The formula is operand / 2(power)number.
Left shift operators
The left shift operator shifts all the bits of a binary number in the left direction.
Binary representation of 4 in bits.
The operator shifts the bits of this binary number to left by 2 positions,the two leftmost bits are discarded.
The formula is operand *2(power)number.
Unsigned shift operator
unsigned shift operator is used to shift the bits of a binary number to right.The operator fills leftmost bits of a binary value with 0 irrespective of whether the number has 0 or 1 at the leftmost bit.
Binary representation of 6in bits.(64 bit representation)
00000000 00000000 00000000 00000110
00000000 00000000 00000000 00000000
Like it on Facebook, +1 on Google, Tweet it or share this article on other bookmarking websites.