def get_bin_list(n, nmax):
    """
    return a list of digits of the binary representation of n
    nmax is the maximum theoretical value of n, used to add 0 at the front of the list if necessary
    """
    if n == 0:
        return [0 for _ in range(len(bin(nmax))-3)]
    n = bin(n)
    digits = []
    for i in range(len(n)-2):
        digits.append(int(n[i+2]))
    while len(digits) < len(bin(nmax))-3:
        digits.insert(0,0)
    return digits