The following ideas are implemented:
The target value is extracted at the end bit, the bit bit is placed at the end of the same type, the target value bit is shifted to the right, and the same type bit bit is shifted to the left.
The bitwise operators of C languages:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7C/DF/wKiom1bZndLRecyCAABFU9abgvw125.png "title="] ERO@L4PFP) 9cqzc{qt1nrr.png "alt=" wkiom1bzndlrecycaabfu9abgvw125.png "/> Implementation code is as follows:
#include <stdio.h>//A bitwise flip of an unsigned shape unsigned int reverse_bit (unsigned int value) {unsigned int num = 0;int i = 0;for (i = 1; I < 32; i++) {num + = value & 1;num <<= 1;value >>= 1;} return num;}
The test cases are as follows:
int main () {unsigned int num = 25;printf ("%u", Reverse_bit (num)); system ("pause"); return 0;}
If there is any deficiency, I hope to correct my mistakes.
This article is from the "Pawnsir It Road" blog, so be sure to keep this source http://10743407.blog.51cto.com/10733407/1747733
"Application of the C-bit operation" How to flip an unsigned integer by bit bit