Write a function rightrot(x,n) that returns the value of the integer x rotated to the right by n operations
I can't see how i can get the bits and put them in the right position without requiring the length of x(the amount of bits).
Am I thinking wrong or do i really need to get the length of x somehow? If so, how would I go about getting this length of x?
The code below is wrong probaply by the way, I just put length_x in to demonstrate my problem.
I hope someone can point me in the right direction.
#include <stdio.h>
unsigned rightrot(unsigned x, int n);
main()
{
unsigned x = 75;
int p, n, y;
p = 5;
n = 3;
y = 45;
printf("%u\n",rightrot(x,n));
}
unsigned rightrot(unsigned x, int n)
{
oldn = (x & ~(~0 << n)) << length_x;
x = x >> n | oldn;
return x;
}