def bin2bytes(x):
    """Convert an array of bits (MSB first) into a string of characters."""
    bits = []
    bits.extend(x)
    bits.reverse()
    i = 0
    out = b''
    multi = 1
    ttl = 0
    for b in bits:
        i += 1
        ttl += b * multi
        multi *= 2
        if i == 8:
            i = 0
            out += bytes([ttl])
            multi = 1
            ttl = 0
    if multi > 1:
        out += bytes([ttl])
    out = bytearray(out)
    out.reverse()
    out = bytes(out)
    return out
