def get_bitslice(obj, topidx, bottomidx):
    """Returns the bits within obj[bottomidx:topidx+1] (Or in architecture format
    obj[topidx:bottomidx])
    """
    obj = obj >> bottomidx

    # Generate a bitmask to get topidx - bottomidx number bits
    mask = 1
    for bit in range(topidx - bottomidx):
        mask = mask << 1
        mask += 1
    return obj & mask