Right Shift Operators :
Syntax :
What does A » x mean :
A >> x
implies shifting the bits of A to the right by x positions. The last x bits are lost this way.
Example :
Lets say
A = 29 ( 11101 ) and x = 2,
so A >> 2 means
0 0 1 1 1 0 1 >> 2
==== -> is lost
========== -----> this sequence of digit shifts to the right by 2 positions
----------------
0 0 0 0 1 1 1 = 7
A >> x
is equal to division by pow(2, x). Think why.
Left shift operators :
Syntax :
What does A « x mean :
A << x
implies shifting the bits of A to the left by x positions. The first x bits are lost this way. The last x bits have 0.
Example : lets say
A = 29 ( 11101 ) and x = 2,
so A << 2 means
0 0 1 1 1 0 1 << 2
============= ------> this sequence of digit shifts to the left by 2 positions
----------------
1 1 1 0 1 0 0 = 116
A << x
is equal to multiplication by pow(2, x). Think why.
1 << x
is equal to pow(2, x).