public int betterSwap(int num,int i,int j){
        if(((num & 1<<i)>>i ^ (num & 1<<j)>>j)  != 0){
            num ^= 1<<i;
            num ^= 1<<j;
        }
        return num;
    }
http://www.careercup.com/question?id=17542662
src/com/interview/bits/SwapTwoBits.java