https://leetcode.com/problems/reverse-bits/ có vẻ đúng :3
PHP Code:
uint32_t reverseBits(uint32_t n) {
int a;
char bef, aft;//before - after
int j, x;
for(int i = 0; i < 16; i++)
{
j = 31 - i;
bef = (n >> i) & 1;
aft = (n >> j) & 1;
x = bef ^ aft;
a = (x << i) | (x << j);
n ^= a;
}
return n;
}
Leave a comment: