Skip to content

小技巧 ​


异或运算 ​

|^|0|1|
|0|0|1|
|1|1|0|
不同为1,相同为0;简单理解为无进位加法

n^n = 0; n^0 = n;

最右边第一个为1的位置 ​

c
r = n & (~n + 1);