def getBits(data, offset, bits=1):
    """
    Get specified bits from integer

    >>> bin(getBits(0b0011100,2))
    '0b1'
    >>> bin(getBits(0b0011100,0,4))
    '0b1100'
    """
    mask = ((1 << bits) - 1) << offset
    return (data & mask) >> offset