关于循环右移的问题
我写了一段循环右移的代码,能编译出来,但是结果根本不对,结果总是得0。希望大侠们能指点一下。代码如下:#include<stdio.h>
unsigned int rotate_right (unsigned int x, int n) /* x为要右移的数,n为右移的位数 */
{
unsigned int high_bit = 0, low_bit = 0, result = 0;
high_bit = (x & (~0u << n));
low_bit = (x & ~(~0u << n));
result = (high_bit >> n) & (low_bit << (32 - n)); /* result为右移后的结果 */
return result;
}
int main()
{
unsigned int x,result;
int n;
scanf("%x, %d", &x, &n);
result = rotate_right (x, n);
printf("%x\n", result);
}