Bitwise recursive addition of two integers | Python program to do recursive addition of two integers ; If bitwise & is 0 , then there is not going to be any carry . Hence result of XOR is addition . ; Driver code
def add ( x , y ) : NEW_LINE INDENT keep = ( x & y ) << 1 ; NEW_LINE res = x ^ y ; NEW_LINE if ( keep == 0 ) : NEW_LINE INDENT return res ; NEW_LINE DEDENT return add ( keep , res ) ; NEW_LINE DEDENT print ( add ( 15 , 38 ) ) ; NEW_LINE