您的位置:首页 > 其它

Exercise 2-8.

2016-02-19 11:20 375 查看
Exercise 2-8.Write a function rightrot(x,n) that returns the value of the integer x rotated

to the right b y npositions.

int unsignedLength()
{
unsigned x = (unsigned)~0;
int i = 0;
while (x != 0)
{
x = x >> 1;
i++;
}
return i;
}

unsigned rightrot(unsigned x, int n)
{
int l = unsignedLength();
int a, b, c;
a = (~0) >> (l - n) | x;
b = x >> n;
c = a << (l - n);
return b | c;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: