def unpack(n, x):
    """Unpacks the integer x into an array of n bits, LSB-first, truncating on overflow."""

    bits = []
    for _ in range(n):
        bits.append((x & 1) != 0)
        x >>= 1
    return bits