Just wasted 10 min thinking about minimum xor


#1

just reverse the the bit and return it, thats it


#2

What is wrong in this logic, Im comparing ith bit with (32-i)th bit, and changing bit values in res accordingly

long res=0;
for (int i=0;i<16;i++) {
    if ( (a&(1<<i)) != 0 && (a&(1<<(31-i))==0) ) {
        res=res|(1<<(31-i));
    }
    if ( (a&(1<<i)) == 0 && (a&(1<<(31-i)) != 0) ) {
        res=res|(1<<i);
    }
}

return res;

#3

I think u need to update the ‘res’ when ith and (32-i)th bit both are 1.Those position have 0 instead of 1 according to ur code