easy solution in java.
public int findComplement(int num) {\n       int x=1,i=1;\n        while(x<=num && i<32)\n        {\n            num=num^x;\n            x=x<<1;\n            i+
    public int findComplement(int num) {\n       int x=1,i=1;\n        while(x<=num && i<32)\n        {\n            num=num^x;\n            x=x<<1;\n            i++;\n        }\n    \n        return num;\n    }
[]