summaryrefslogtreecommitdiffstats
path: root/2/8.c
blob: 2d573015979bd4ec84d242e5fd62e96147da7a40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>

/* rotates x to the right by n positions */
unsigned rightrot(unsigned x, int n);

int main(int argc, char *argv[]) {
    unsigned x;

    x = rightrot(0x7, 3);
    printf("rotated: %x\n", x);

    return 0;
}

unsigned rightrot(unsigned x, int n) {
    return (x >> n) | (x << (32 - n));
}