bit manipulation

操作符

说明

&

|

^

异或

<<

左移(右边补0)乘2

>>>

逻辑右移(左边补0)无符号除2

>>

算数右移(左边补符号位)除2

https://www.interviewcake.com/concept/java/bit-shift

LeetCode:

bit trick

取出最右端为 ‘1’ 的位

用 a &= -a 来取出最右端为 ‘1’ 的位

https://www.cser.club/leetcode/#/leetcode/260.SingleNumberIII

交换0和1

Most elegant way to change 0 to 1 and vice versa

异或1,或者 做减法

或者

Last updated

Was this helpful?