Extract ' k ' bits from a given position in a number . | Function to extract k bits from p position and returns the extracted value as integer ; number is from where ' k ' bits are extracted from p position
def bitExtracted ( number , k , p ) : NEW_LINE INDENT return ( ( ( 1 << k ) - 1 ) & ( number >> ( p - 1 ) ) ) ; NEW_LINE DEDENT number = 171 NEW_LINE k = 5 NEW_LINE p = 2 NEW_LINE print " The ▁ extracted ▁ number ▁ is ▁ " , bitExtracted ( number , k , p ) NEW_LINE