def extract_bits(value, first, last):
    """
    Extract some bits from int `value`
    :param int value:
    :param int first:
    :param int last:
    :return: int
    """
    value >>= first
    mask = ~((-1) << (last - first + 1))
    return value & mask