def bits_to_bytes(a, reverse=True):
    """
    Function that converts bit string into a given number of bytes.

    :param str a: Bytes to convert.
    :param bool reverse: Whether or not to reverse the byte list.

    :return: List of bytes.
    """
    bytelist = []
    if len(a) % 8 != 0:
        padding = 8 - len(a) % 8
        a = '0' * padding + a
    for i in range(len(a) // 8):
        bytelist.append(int(a[8 * i:8 * (i + 1)], 2))
    if reverse:
        bytelist.reverse()
    return bytelist
