- 找到最低位的 1
n & -n;
/*
6 ^ -6 = 110 ^ 010 = 010
*/
- 消掉最低位的 1
n & (n - 1);
- 檢查是不是
const isPowerOfTwo = x !== 0 && n & (n - 1 === 0);
XOR
- Swap two varibles
a = 4;
b = 6;
a = a ^ b;
b = a ^ b;
a = a ^ b;
console.log(a, b); // 6 4
n & -n;
/*
6 ^ -6 = 110 ^ 010 = 010
*/
n & (n - 1);
const isPowerOfTwo = x !== 0 && n & (n - 1 === 0);
a = 4;
b = 6;
a = a ^ b;
b = a ^ b;
a = a ^ b;
console.log(a, b); // 6 4