Maximum XOR of Two Numbers in an Array | C ++ implementation ; Function to return the maximum xor ; Calculating xor of each pair ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int max_xor ( int arr [ ] , int n ) { int maxXor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { maxXor = max ( maxXor , arr [ i ] ^ arr [ j ] ) ; } } return maxXor ; } int main ( ) { int arr [ ] = { 25 , 10 , 2 , 8 , 5 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << max_xor ( arr , n ) << endl ; return 0 ; }