C# Think XOR beats 80% runtime
Intuition\n Describe your first thoughts on how to solve this problem. \nThink XOR\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink XOR\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(log(n))$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic class Solution {\n    public int MinChanges(int n, int k) {\n        int count = 0;\n        while( n > 0 || k > 0)\n        {\n            // Fetch last bit of the number\n            int nBit = n & 1;\n            int kBit = k & 1;\n\n            // case1: if both the bits are same, xor will give the result as 0\n            // case2: if both the bits are different, xor will give result as 1\n                // case 2.1: if the nth is 1, we can safely turn it into 0\n                // case 2.2: if the kth bit is 1, then we cannot change the bit from 1 to 0 hence return -1\n\n            int xor = nBit ^ kBit;\n            if(xor == 1 && kBit == 1) return -1;\n            if(xor == 1) count ++;\n\n            // right shift the bit by 1 (division operation)\n            n >>= 1;\n            k >>= 1;\n        }\n\n        return count;\n    }\n}\n```
['C#']