from typing import List


def bitarray_to_bytes(bitarray: List[int]) -> bytes:
    """Convert an array of bits to bytes.

    Args:
        bitarray: Bit array to be converted.

    Returns:
        Input array in bytes.
    """
    n_bits = len(bitarray)
    n_bytes = (n_bits + 7) >> 3
    int_array = [0] * n_bytes
    for i in range(n_bits):
        int_array[i >> 3] |= bitarray[i] << (i & 7)
    return bytes(int_array)