[JAVA] beats 100% user in java
\n\n# Approach\nbit masking and bit shifting\n# Complexity\n- Time complexity: O(31)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n A
\n\n# Approach\nbit masking and bit shifting\n# Complexity\n- Time complexity: O(31)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int minChanges(int n, int k) {\n        int c = 0;\n        for(int i=0;i<31;i++){\n            int mask = (1 << i);\n\n            int b1 = n & mask;\n            int b2 = k & mask;\n\n            if ( b2 == 0 && b1 !=0){\n                n = n^mask;\n                c++;\n            }\n        }\n        return (n == k ? c: -1);\n    }\n}\n```
['Java']