C examples for Function:Utility Function
Create a function to get the value of the integer x rotated to the right by n positions.
#include <stdio.h> int rightroc(int x, int n); int main(void){ printf("%u\n", rightroc(5432, 3)); return 0;/*from w w w . ja va2 s . c o m*/ } int rightroc(int x, int n){ while (n-- > 0){ if(x & 1) x = (x >> 1) | ~(~0U >> 1); else x = x >> 1; } return x; }