#include #include #include /* Exercise 2-8. Write a function rightrot(x,n) that returns the value of the (unsigned) integer x rotated to the right by n bit positions. */ unsigned rightrot(unsigned x, int n) { #ifndef AMD64 //right rotate assembly instruction is used if the arch is AMD64. for (int i=0;i> 1); x |= (1UL << ((sizeof(x) * CHAR_BIT)-1));} /* if the lowest bit is 0, be don't need to rotate */ else{x = (x >> 1);} } #endif return x; } int main(void) { printf("%u\n", rightrot(0xAAA,2147483647)); return 0; }