Find a value whose XOR with given number is maximum | C ++ implementation of the above approach ; Function To Calculate Answer ; Find number of bits in the given integer ; XOR the given integer with poe ( 2 , number_of_bits - 1 and print the result ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calculate ( int X ) { int number_of_bits = 8 ; return ( ( 1 << number_of_bits ) - 1 ) ^ X ; } int main ( ) { int X = 4 ; cout << " Required ▁ Number ▁ is ▁ : ▁ " << calculate ( X ) << endl ; return 0 ; }