Task: Rotations
You will solve the exercise starting from the file rotations.c
located in the directory tasks/rotations/
.
Implement left and right rotations for 32-bit integers in C.
TIP: The rotation operation (also known as circular shift) is similar to the shift operation, with the only difference being that the empty space generated by the shift is filled with the discarded bit.
Example of left rotation by one bit:
NOTE:
rotate_left(0x80000000, 1) = 1 rotate_right(0x00000001, 16) = 65536
To test the implementation, enter the tests/
directory and run:
make check
In case of a correct solution, you will get an output such as:
./run_all_tests.sh
test_rotate_left ........................ passed ... 33
test_rotate_right ........................ passed ... 33
test_rotate_both ........................ passed ... 34
Total: 100/100
If you’re having difficulties solving this exercise, go through this reading material.