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.
For example:
On the four-position machine This value includes the following members:
00000000000000000000000000011001
After flipping: (2550136832)
10011000000000000000000000000000
The program results return:
2550136832
The result of the observation output is the value of the binary reverse order of the input number.
The code is as follows:
#include <stdio.h> #include <stdlib.h>unsigned int revease_bit (unsigned int val) {int i;unsigned int ret=0; The two statements in for (i=0;i<32;i++) {Ret<<=1;//for cannot be interchanged ret|= ((val>>i) &1),/*val right-shift I-bit, and "1" take the value of binary each bit with operation, Again and RET or operation, the last shift, so that it in reverse order. You can also use the following notation: (add header file #include<math.h>) ret + = ((num >> i) & 1) *pow (2, 31-i); */}return ret;} int main () {unsigned int val;scanf ("%u", &val);p rintf ("%u\n", Revease_bit (Val)),//%u for unsigned decimal output system ("pause"); return 0;}
This article is from the "Materfer" blog, make sure to keep this source http://10741357.blog.51cto.com/10731357/1708429
Write function return value value of binary mode from left to right after rollover