def reversedbinary(i,numbits):
    """Takes integer i and returns its binary representation
    as a list, but in reverse order, with total number of bits
    numbits. Useful for trying every possibility of numbits choices
    of two."""
    num = i
    count = 0
    revbin = []
    while count < numbits:
        revbin.append(num%2)
        num = num//2
        count += 1
    return revbin