#include <stdio.h> #include <stdlib.h>unsigned int Reverse_bit (unsigned x) { unsigned int a; unsigned int b=1,i,t; a = n&b; //bitwise OR for (i = 0; i < 31; i++) { a <<= 1; //left shift n >>= 1; //right shift t = n&b; a = a | t; } return a; //returns the reversed number of}int main () { unsigned int value; printf ("Enter the number you want to invert:"), scanf ("%d", &value), printf ("The number after inversion is:%d\n", reverse_bit (value)); //call inversion function and output system ("pause"); return 0;}
This article is only in the learning process of their own ideas, can only achieve simple functions, may not consider the optimization of the program, and the code written by the great God there is a certain gap, if the great God found the problem, please enlighten me, if you have a better way, may wish to share, thank you!
This article is from the "Sharing Progress" blog, be sure to keep this source http://xmwen1.blog.51cto.com/10730069/1706063
Write a simple function: let a binary code with an unsigned number of bits reverse, i.e. 1->32,32->1;