# 函数返回值的二进制位模式从左向右反转

## 标题 ##函数返回值的二进制位模式从左向右反转

unsigned int reverse_bit(unsigned int value);

00000000000000000000000000011001

10011000000000000000000000000000

2550136832

#define  _CRT_SECURE_NO_WARNINGS
#include<windows.h>
#include<stdio.h>
#include<math.h>
unsigned int  reverse_bit(unsigned int value)
{
int i = 31;
int m;
int sum = 0;
while (value != 0)
{
m = value & 1;      //取余
value = value >> 1; //除2
sum = sum + m * pow(2, i);    //pow(2,i)表示2的i次方
i--;
}
return sum;
}
int main()
{
unsigned long int a;
a = reverse_bit(25);
printf("%u", a);//长整形
system("pause");
return 0;
}

int main()
{
unsigned int a;
a=reverse_bit(25);
printf("%d",a);
return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include<windows.h>
#include<stdio.h>
int reverse_bit(int value)
{
int i;
int sum=0;
int bit;

for(i=0;i<32;i++)
{
sum = sum << 1;
bit = value & 1;
sum = sum | bit;
value = value >> 1;
}
return sum;
}
int main()
{
long a;
a=reverse_bit(25);
printf("%u",a);
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120