Removebitnum, i: remove a bit at specific position. For example: Input: num  10101 21 removebitnum, 2: output  1001 9 removebitnum, 4: output  101 5 removebitnum, 0: output  1010 10
def remove_bit(num, i):
    mask = num >> (i + 1)
    mask = mask << i
    right = ((1 << i) - 1) & num
    return mask | right
