Bit Manipulation
bit manipulation
Basic Operations
Tricks
http://www.jiuzhang.com/tutorial/bit-manipulation/84
n & (n-1)
remove last1
in binary
https://leetcode.com/problems/power-of-two/description/ https://leetcode.com/problems/number-of-1-bits/description/
determine odd/even:
n % 2
orn & 1
,n & 1
is better, unsigned integer can be larger than Integer.MAX_VALUEget last bit:
x & -x
+, -, *, /
operations
+, -, *, /
operationsLast updated