Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Exercise 2-8.
- * lWrite a function rightrot(x,n) that returns the value of the integer x
- * rotated to the right by n positions.
- */
- #include <stdio.h>
- unsigned int
- rightrot(unsigned int x, int n) {
- unsigned int sz = sizeof(unsigned int)*8;
- return (x>>n) | (x<<(sz - n));
- }
- int
- main() {
- unsigned int x,y;
- x = 0x0f;
- y = rightrot(x,2);
- printf("y = %X\n", y);
- }
Advertisement
Add Comment
Please, Sign In to add comment