I dont understand the solution

int num = x^y;
int msb=0;
while(num!=0) {
num=num>>1;
msb++;
}
int result = 1;
while(msb–) {
result=result<<1;
}
cout<<result-1;

can you explain line by line with example ?

@premang
To make things easier to understand I have changed the variable name and minor syntaxes.
int num = x ^ y; //XOR of x and y
int bits = 0;
while (num != 0) {
num = num >> 1; //num = num/2
bits++; //no of bits in num
}
int result = 1;
result = result << bits;// equivalent to result = pow(2, bits);
cout << result - 1;//result is all the bits set equivalent to 2^(bits)-1

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.