On this pageBitwiseCount no. of set bitmask.bit_count()All subsets of a maskm = mask; s = []while m: s.append(m) m = (m - 1) & maskx if num = x * 2 ** yx = num // (num & -num)a ** bres = 1while b: if b & 1: res = res * a a *= a b >>= 1