I am not sure if the shift direction is correct but this is the basic idea to do a circular shift. Please keep in mind that the function assumes that the number of bits to shift will be in the range 0-31. You can allow any value but implimenting the % operator on shift and mod by 31 (i think).
Matt
Code:
int CShift(int value, int shift)
{
int high = 0;
int low = 0;
if(shift<0)
{
// left shift
int sh = shift*-1;
high = value<<sh;
low = value>>(32-sh);
}
else
{
// right shift
low = value>>shift;
high = value<<(32-shift);
}
return high | low;
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.