From ad0fe282e99f42a90b2e378832bc911b3e805fa0 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 1 Dec 2021 21:03:40 +0800 Subject: 2.8 --- 2/8.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 2/8.c diff --git a/2/8.c b/2/8.c new file mode 100644 index 0000000..2d57301 --- /dev/null +++ b/2/8.c @@ -0,0 +1,17 @@ +#include + +/* 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)); +} \ No newline at end of file -- cgit v1.2.3