Smallest pair of integers with minimum difference whose Bitwise XOR is N | C ++ program for the above approach ; Function to find the numbers A and B whose Bitwise XOR is N and the difference between them is minimum ; Find the MSB of the N ; Find the value of B ; Find the value of A ; Print the result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findAandB ( int N ) { int K = log2 ( N ) ; int B = ( 1 << K ) ; int A = B ^ N ; cout << A << ' ▁ ' << B ; } int main ( ) { int N = 26 ; findAandB ( N ) ; return 0 ; }