Other approach for xor profit problem

is there any short approach to solve the problem. or we need to solve it by applying loops and then find max between them.

@ankityadav943 hey Ankit yeah there is another approach.

#include < iostream >
using namespace std;
int main(){
int a,b;
cin>>a>>b;
int xr = a ^ b;
int msbpos=0;
while(xr){
msbpos + +;
xr = xr>>1;
}
int maxxr=0;
int x=1;
while(msbpos- -){
maxxr +=x;
x = x<<1;
}

cout<<maxxr;

}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.