// Type your C++ code and click the "Run Code" button!
// Your code output will be shown on the left.
// Click on the "Show input" button to enter input data to be read (from stdin).
#include <iostream>
using namespace std;
typedef unsigned int uint;
uint swap_bits(uint x, uint i, uint j) {
uint l = (x >> i) & 1;
uint h = (x >> j) & 1;
if(l ^ h) {
x ^= (1U << i) | (1U << j);
}
return x;
}
uint reverse_bit(uint x) {
uint c = sizeof(x) * 8;
for(int i = 0; i <= c/2; i++) {
x = swap_bits(x, i, c-i);
}
return x;
}
int main() {
uint x = 5;
cout<<x<<endl;
x = reverse_bit(x);
cout<<x<<endl;
return 0;
}
欢迎关注微信公众号——计算机视觉: