Realize:
00000000000000000000000000011001
10011000000000000000000000000000
This flip
Method One and method two ideas are roughly the same, can method two but very troublesome.
Method One (Simple)
#include <stdio.h> #include <math.h>unsigned int reverse_bit (unsigned int Value) { int i = 0; unsigned int value ; unsigned int num = 0;for (i = 1; i <= 32; i++) { Value = value; int b = ((value%2) &&1); num = num + b* (Pow (2, (32 - i))); value= value >> 1;} Return num;} Int main () { unsigned int number = 25; printf ("%u", reverse_bit (number));} Method two (thought simple but write very complex, I do not know how I think out of)
#include <stdio.h> #include <math.h>unsigned int zhishu (Int x, int cishu) { Unsigned int num = pow (2, cishu);return (x*num);} Int num_sing (Int max) {if (max % 2 == 0) {return 0;} else{return 1;}} Unsigned int fzsign (unsigned int a) {unsigned int num = 0;int sing = num_sing (a);int cishu = 0 + sing;unsigned int tmp = a;unsigned int b = 0;while (a != sing) {a = a / 2;cishu+ +;} /*printf ("%d\n", cishu); */int sings = num_sing (TMP); Int tmp2 = cishu;cishu = cishu - 1;while (tmp != sings) {b = tmp % 2;tmp = tmp / 2;num = num + zhishu (B, cishu); cishu--;} num = num + sings;num = num << (32&NBSP;-&NBSP;TMP2); return num;} Int main () {unsigned int a = 25;unsigned int num=fzsign (a);p rintf ("%u", num);} two like a hodgepodge!!!
This article is from the "Traces" blog, be sure to keep this source http://wpfbcr.blog.51cto.com/10696766/1703666
Left and right flip binary number = = "tedious and streamlined