[cpp]
#include <iostream>
typedef unsigned int uint;
uint switch_digit(uint i, uint j, uint n)
{
uint i_bit = ((n >> i) & 1);
uint j_bit = ((n >> j) & 1);
if (i_bit ^ j_bit) // should be swithed
{
n = (1 << j) ^ (1 << i) ^ n;
}
return n;
}
uint reverse_integer(uint n)
{
uint length = sizeof(uint) * 8;
uint low = 0;
uint high = length - 1;
while (low < high)
{
n = switch_digit(low++, high--, n);
}
return n;
}
int main()
{ www.2cto.com
uint n = 1;
n = reverse_integer(n);
return 0;
}