Bit Manipulation
Bitwise NOT
~valNOT 0111 (decimal 7)
= 1000 (decimal 8)for (int i = val; ~i; --i)for (int i = val; i >= 0; --i)Set the ith bit
ith bitmask |= 1 << iUnset the ith bit
ith bitmask &= ~(1 << i)Toggle the ith bit
ith bitCheck if ith bit is set
ith bit is setSet the ith bit with x
ith bit with xGet the lowest bit
Count bit 1s
Count trailing zeros
Count leading zeros
Check if n is power of 2
n is power of 2Traverse all the subsets
Complement of a subset
Traverse subsets of a set mask
maskGiven N elements, traverse subsets of size K (Gosper's Hack)
N elements, traverse subsets of size K (Gosper's Hack)Traverse subsets of subsets
Calculate subset sums
Generate logs array
logs arrayReference
Last updated