Yield integers of dtype bit-length reverting their bit-order.

    >>> list(chunkreverse([0b10000000, 0b11000000, 0b00000001], 'B'))
    [1, 3, 128]

    >>> list(chunkreverse([0x8000, 0xC000, 0x0001], 'H'))
    [1, 3, 32768]

def chunkreverse(integers, dtype='L'):
    """Yield integers of dtype bit-length reverting their bit-order.

    >>> list(chunkreverse([0b10000000, 0b11000000, 0b00000001], 'B'))
    [1, 3, 128]

    >>> list(chunkreverse([0x8000, 0xC000, 0x0001], 'H'))
    [1, 3, 32768]
    """
    if dtype in ('B', 8):
        return map(RBYTES.__getitem__, integers)

    fmt = '{0:0%db}' % NBITS[dtype]

    return (int(fmt.format(chunk)[::-1], 2) for chunk in integers)