def get_nbits_to_copy(i: int, j: int, n: int) -> int:
    """Returns the number of bits to copy during a single byte process.
    :param i: the number of the total bits processed.
    :param j: the number of bits processed on current base type.
    :param n: the number of bits current base type occupy.
    """
    return min(n - j, 8 - (j % 8), 8 - (i % 8))