Check whether the binary equivalent of a number ends with given string or not | Function returns true if s1 is suffix of s2 ; Function to check if binary equivalent of a number ends in "111" or not ; To store the binary number ; Count used to store exponent value ; Driver code
def isSuffix ( s1 , s2 ) : NEW_LINE INDENT n1 = len ( s1 ) NEW_LINE n2 = len ( s2 ) NEW_LINE if ( n1 > n2 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( n1 ) : NEW_LINE INDENT if ( s1 [ n1 - i - 1 ] != s2 [ n2 - i - 1 ] ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT def CheckBinaryEquivalent ( N , s ) : NEW_LINE INDENT B_Number = 0 ; NEW_LINE cnt = 0 ; NEW_LINE while ( N != 0 ) : NEW_LINE INDENT rem = N % 2 ; NEW_LINE c = pow ( 10 , cnt ) ; NEW_LINE B_Number += rem * c ; NEW_LINE N //= 2 ; NEW_LINE cnt += 1 ; NEW_LINE DEDENT bin = str ( B_Number ) ; NEW_LINE return isSuffix ( s , bin ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 23 ; NEW_LINE s = "111" ; NEW_LINE if ( CheckBinaryEquivalent ( N , s ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT