Problem Description:
To write a function:
unsigned int reverse_bit (unsigned int value);
The return value of this function values the value of the BITS mode from left to right.
Such as:
On 32-bit machines 25 This value contains the following members:
00000000000000000000000000011001
After flipping: (2550136832)
10011000000000000000000000000000
The program results return:
2550136832
Code implementation:
#include <stdio.h> #include <math.h>unsigned int reverse_bit (unsigned int value) {int i=0; unsigned int sum=0; for (i=0;i<32;i++) {sum+= ((value>>i) &1) *pow (2,31-i);} return sum;} int main () {unsigned int value=25;//00000000 00000000 00000000 00011001 int ret=reverse_bit (value); printf ("%u\n", ret); r Eturn 0;}
The result is: 2550136832. 10011000 00000000 00000000 00000000
This article is from the "Pzd Chuan Feng" blog, please make sure to keep this source http://xujiafan.blog.51cto.com/10778767/1711236
C Language of bits flip, difficult difficult!!!