def extract_bits(data, shift, length):
    bitmask = ((1 << length) - 1) << shift
    return ((data & bitmask) >> shift)

# ==================================================
Extract a portion of a bit string. Similar to substr().
dataset/ETHPy150Open SawdustSoftware/simpleflake/simpleflake/simpleflake.py/extract_bits