def bitfieldify(buff, count):
    """Extract a bitarray out of a bytes array.

    Some hardware devices read from the LSB to the MSB, but the bit types available prefer to put pad bits on the LSB side, completely changing the data.

    This function takes in bytes and the number of bits to extract
    starting from the LSB, and produces a bitarray of those bits.

    """
    databits = bitarray()
    databits.frombytes(buff)
    return databits[len(databits)-count:]
Extract a bitarray out of a bytes array.

    Some hardware devices read from the LSB to the MSB, but the bit types available prefer to put pad bits on the LSB side, completely changing the data.

    This function takes in bytes and the number of bits to extract
    starting from the LSB, and produces a bitarray of those bits.