basics · intermediate · ~15 min
Circularly shift bits toward the LSB.
Implement:
uint32_t rotr32(uint32_t x, int n);
Rotate x right by n positions. n>=0; rotation is mod 32.
A 32-bit value and a shift n.
The rotated value.
x is 32-bit unsigned integer; n is shift count.
#include <stdint.h>
/* Rotate x right by n positions (n>=0; rotation is mod 32). */
uint32_t rotr32(uint32_t x,int n){ (void)n; return x; }
Undefined shift behavior when shift count equals or exceeds word width.
n == 0, n == 31, n >= 32.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.