unsigned int reverse(unsigned int value);
这个函数的返回值value的二进制位模式从左到右翻转后的值。
如:
在32位机器上输入25这个值包含下列各位:
00000000000000000000000000011001
翻转后:
10011000000000000000000000000000
程序结果返回:
2550136832
#include<stdio.h>
#include<math.h>
#include<windows.h>
unsigned int reverse(unsigned int value)
{
int j = 0;
unsigned int num = 0;
for (j = 31; j >= 0; value /= 2,j--)
{
num += ((value%2) * pow(2, j));
}
return num;
}
int main()
{
int i = 0;
int set = 0;
scanf_s("%d", &i);
set = reverse(i);
printf("%u", set);
system("pause");
return 0;
}