XNOR of two numbers | javascript program to find XNOR of two numbers ; Make sure a is larger ; swapping a and b ; ; for last bit of a ; for last bit of b ; counter for count bit and set bit in xnornum ; to make new xnor number ; for set bits in new xnor number ; get last bit of a ; get last bit of b ; Check if current two bits are same ; counter for count bit ; Driver Function
function xnor ( a , b ) { if ( a < b ) { let t = a ; a = b ; b = t ; } if ( a == 0 && b == 0 ) return 1 ; let a_rem = 0 ; let b_rem = 0 ; let count = 0 ; let xnornum = 0 ; while ( true ) { a_rem = a & 1 ; b_rem = b & 1 ; if ( a_rem == b_rem ) xnornum |= ( 1 << count ) ; count ++ ; a = a >> 1 ; b = b >> 1 ; if ( a < 1 ) break ; } return xnornum ; } let a = 10 , b = 50 ; document . write ( xnor ( a , b ) ) ;