khalfella

ansi_c_pg47_ch02_ex08.c

Nov 2nd, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. /*
  2. * Exercise 2-8.
  3. * lWrite a function rightrot(x,n) that returns the value of the integer x
  4. * rotated to the right by n positions.
  5. */
  6.  
  7.  
  8. #include <stdio.h>
  9.  
  10. unsigned int
  11. rightrot(unsigned int x, int n) {
  12.  
  13. unsigned int sz = sizeof(unsigned int)*8;
  14. return (x>>n) | (x<<(sz - n));
  15.  
  16. }
  17.  
  18. int
  19. main() {
  20. unsigned int x,y;
  21. x = 0x0f;
  22. y = rightrot(x,2);
  23. printf("y = %X\n", y);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment