diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-01 21:03:40 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-01 21:03:40 +0800 |
| commit | ad0fe282e99f42a90b2e378832bc911b3e805fa0 (patch) | |
| tree | 506c0f346dc3e1cbb624ae002c7c09de49b65e56 /2 | |
| parent | 38b5d067f60d752ac5b64612356558202e12d43e (diff) | |
| download | k&r-exercises-ad0fe282e99f42a90b2e378832bc911b3e805fa0.tar.gz | |
2.8
Diffstat (limited to '2')
| -rw-r--r-- | 2/8.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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 |
