'Reads `count` bits and returns an uint, MSB read first.
May raise BitReaderError if not enough data could be read or
IOError by the underlying file object.'

def bits(self, count):

    if (count < 0):
        raise ValueError
    if (count > self._bits):
        n_bytes = (((count - self._bits) + 7) // 8)
        data = self._fileobj.read(n_bytes)
        if (len(data) != n_bytes):
            raise BitReaderError('not    enough    data')
        for b in bytearray(data):
            self._buffer = ((self._buffer << 8) | b)
        self._bits += (n_bytes * 8)
    self._bits -= count
    value = (self._buffer >> self._bits)
    self._buffer &= ((1 << self._bits) - 1)
    assert (self._bits < 8)
    return value
