Choose X such that ( A xor X ) + ( B xor X ) is minimized | c ++ implementation of above approach ; finding X ; finding Sum ; Driver code
#include <iostream> NEW_LINE using namespace std ; int findX ( int A , int B ) { return A & B ; } int findSum ( int A , int B ) { return A ^ B ; } int main ( ) { int A = 2 , B = 3 ; cout << " X ▁ = ▁ " << findX ( A , B ) << " , ▁ Sum ▁ = ▁ " << findSum ( A , B ) ; return 0 ; }