Left and right shift operators (<< and >>) are already available in C++. However, I couldn\'t find out how I could perform circular shift or rotate operations.
In details you can apply the following logic.
If Bit Pattern is 33602 in Integer
1000 0011 0100 0010
and you need to Roll over with 2 right shifs then: first make a copy of bit pattern and then left shift it: Length - RightShift i.e. length is 16 right shift value is 2 16 - 2 = 14
After 14 times left shifting you get.
1000 0000 0000 0000
Now right shift the value 33602, 2 times as required. You get
0010 0000 1101 0000
Now take an OR between 14 time left shifted value and 2 times right shifted value.
1000 0000 0000 0000 0010 0000 1101 0000 =================== 1010 0000 1101 0000 ===================
And you get your shifted rollover value. Remember bit wise operations are faster and this don't even required any loop.