/* Exercise 2.8 from "The C programming language" book by K&R */
#include <stdio.h>
/* rotates x to right for n bits */
unsigned char rightrot(unsigned char x, unsigned n)
{
while (n-- != 0)
if (x & 1)
x = (x >> 1) | ~(~0 >> 1);
else
x = x >> 1;
return x;
}
int main(void)
{
printf("%d\n", rightrot(0xFF, 1));
return 0;
}
----------