Google Interview Question

Reverse bits of a digit

Interview Answer

Anonymous

Jan 18, 2011

I think you should reverse bits of an integer. If you have only a 8 bit integer then you can make like this: int reverse(int x) { x = ((x & 0xAA) >> 1) | ((x & 0x55) > 2) | ((x & 0xCC) > 4) | ((x & 0x0F) << 4); return x; }