Java Soln if you don't know Bit Manipulation(Just like me)
\nclass Solution {\n    public int bitwiseComplement(int n) {\n        \n        if(n ==0) return 1 ; //If we have 0, the complement will be 1\n        \n      
```\nclass Solution {\n    public int bitwiseComplement(int n) {\n        \n        if(n ==0) return 1 ; //If we have 0, the complement will be 1\n        \n        // next = Just greater no. which is Power of 2\n        //Using the formulae\'loga b = log10 b / log10 a\' we can calculate log to any base\n        int next = (int)(Math.log(n)/Math.log(2)) ;\n        \n        /* Next now hold the just greater no. which is a power of 2 of te given no.\n         *  Eg: if n = 14  than next = 16 which is 2^4 which is a power of 2 */ \n            next = (int)Math.pow(2,next+1); \n        \n        /*  Now next = 16 and by OBSERVATION** we can say that the compliment of a no. \n         *  is the difference between next and n. But we need to substract 1 from the\n         *  result to get the ans */\n        return next - n - 1;\n        \n    }\n}\n```\n**OBSERVATION :**** If a binary no. is subtracted from a no. which has all digits as 1\'s for eg: 111, 1111, 111111 etc it will give the complement of the no. So to get 111 (7 in decimal) we  need to substract 1 from 1000 (8 in decimal)  wich gives the previous all 1\'s digit binary no. . Thus we are substracting 1 in the ans to get a no. just before the 2^n containing all 1\'s digit.
['Java']