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

def extract_bits ( data , shift , length ) : bitmask = ( ( ( 1 << length ) - 1 ) << shift ) return ( ( data & bitmask ) >> shift )
extract a portion of a bit string .