Find all possible pairs with given Bitwise OR and Bitwise XOR values | C ++ code for the above approach ; Function to find pairs with XOR equal to A and OR equal to B ; Iterate from 1 to B ; Check if ( i OR y ) is B ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findPairs ( int A , int B ) { for ( int i = 1 ; i <= B ; i ++ ) { int y = A ^ i ; if ( y > 0 and ( i y ) == B ) { cout << i << " ▁ " << y << endl ; } } } int main ( ) { int A = 8 , B = 10 ; findPairs ( A , B ) ; return 0 ; }