@classmethod
def getbits(cls, bitstream, attrib, start, n):
    """Return an integer of n bits at the 'start' offset

           Note: code from miasm/arch/mips32/arch.py
        """
    if not n:
        return 0
    o = 0
    while n:
        offset = start // 8
        n_offset = cls.endian_offset(attrib, offset)
        c = cls.getbytes(bitstream, n_offset, 1)
        if not c:
            raise IOError
        c = ord(c)
        r = 8 - start % 8
        c &= (1 << r) - 1
        l = min(r, n)
        c >>= r - l
        o <<= l
        o |= c
        n -= l
        start += l
    return o
