ztlevi
7/14/2017 - 8:46 PM

bitwise operator

bitwise operator

# operator | and or
>>> set([1,2,3]) | set([4])
set([1, 2, 3, 4])
>>> set([1,2,3]) or set([4])
set([1, 2, 3])
>>> set([1,2,3]) or set([])
set([1, 2, 3])
>>> set([1,2,3]) | set([])
set([1, 2, 3])
# & operator
a = 6
b = a & -a
# b = 2
# a & -a will return a's first non-0 bit
# a & a's complement
# e.g. 6: 1010, -6: 0110, a&-a = 2 = 0010