用c语言实现 一个数二进制位从左到右的翻转

来源:互联网 发布:java target runtime 编辑:程序博客网 时间:2024/05/29 17:04

编写函数

unsigned int  reverse_bit(unsigned int value);

这个函数的返回值

value的二进制位模式从左到右翻转后的值。

如在32位机器上25这个值包含下列各位:

00000000000000000000000000011001

翻转后:(2550136832)

10011000000000000000000000000000

 


#include <stdio.h>  unsigned int  reverse_bit(unsigned int value)   {   int a=0;int b=0;int c=0;for(a=0;a<32;a++){c=c<<1;b=value&1;value=value>>1;c=c|b;}       return c;  }  int main()  {       printf("%u\n",reverse_bit(25));      return 0;  }


0 0
原创粉丝点击