Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000).
unsigned int reverse_bits(unsigned int value) { unsigned int answer; unsigned int i; answer = 0; /*把一个unsigned int 数字1一直左移,直到它变成全0的时候,也就得到了该机器内unsigned int的长度*/ for (i = 1; i != 0; i <<= 1) { answer <<= 1; if (value & 1) { answer |= 1; } value >>= 1; } return answer; }