In C when you do something like this:
char var = 1;
while(1)
{
var = var << 1;
}
In the 8th iteration the “<<” operator will shift out the 1 and var will be 0. I need to perform a shift in order to mantain the bit shifting. In other words I need this:
initial —– 00000001
1st shift — 00000010
2nd shift – 00000100
3rd shift – 00001000
4th shift – 00010000
5th shift — 00100000
6th shift — 01000000
7th shift – 10000000
8th shift – 00000001 (At the 8th shift the one automatically start again)
Is there something equivalent to “<<” but to achieve this?
Yes, you can use a circular shift. (Although it isn’t a built-in C operation, but it is a CPU instruction on x86 CPUs)