Maximum value of B less than A such that A ^ B = A + B | C ++ implementation to find maximum value of B such that A ^ B = A + B ; Function to find the maximum value of B such that A ^ B = A + B ; Binary Representation of A ; Loop to find the negation of the integer A ; Output ; Driver code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void maxValue ( int a ) { string c = bitset < 3 > ( a ) . to_string ( ) ; string b = " " ; for ( int i = 0 ; i < c . length ( ) ; i ++ ) { if ( ( c [ i ] - '0' ) == 1 ) b += '0' ; else b += '1' ; } cout << bitset < 3 > ( b ) . to_ulong ( ) ; } int main ( ) { int a = 4 ; maxValue ( a ) ; return 0 ; }