Bitwise recursive addition of two integers | Javascript 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
function add ( x , y ) { let keep = ( x & y ) << 1 ; let res = x ^ y ; if ( keep == 0 ) return res ; return add ( keep , res ) ; } document . write ( add ( 15 , 38 ) ) ;