#NEWLINE# def extract_bits( data , shift , length ) : #NEWLINE# #INDENT# 'Extract a portion of a bit string. Similar to substr().' #NEWLINE# bitmask = ( ( ( 1 << data ) - 1 ) << shift ) #NEWLINE# return ( ( data & bitmask ) >> shift )