summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--2/8.c17
1 files changed, 17 insertions, 0 deletions
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 <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));
+} \ No newline at end of file