Easy Solution using Bitwise Operators
```\nclass Solution {\n    public static int findComplement(int num) {\n        //Q476\n        //Ex for 5\n        //Using XOR operator - 0-->1 and 1-->0 that 
```\nclass Solution {\n    public static int findComplement(int num) {\n        //Q476\n        //Ex for 5\n        //Using XOR operator - 0-->1 and 1-->0 that is what we need(Complement)\n        //101 ^ 111 = 010 i.e., the ans. \n        // 111 is the required mask in this case\n        //For calculating mask, we take the value of highest one bit\n        //5 = 101 in binary. Highest one bit = 100\n        //If we left-shift this it will become 1000\n        //1000 - 1 = 111 in binary that is the required mask\n        int mask = (Integer.highestOneBit(num)<<1) - 1;\n        return num ^ mask;\n    }\n}
['Java']