C++ || O(31) || Bit Manipulation
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach:\n for all bits, check if n is set as 1 and k is set as 0\n count these occ
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach:**\n* for all bits, check if `n is set as 1` and `k is set as 0`\n* count these occurrence and modify `n`\n\n```\nclass Solution {\npublic:\n    int minChanges(int n, int k) {\n        int c = 0;\n        for(int i=0;i<31;i++){\n            int bit_mask = (1<<i); // (1) (1 0) (1 0 0)....\n            \n            int b1 = n & bit_mask; \n            int b2 = k & bit_mask; \n            \n            if(b2 == 0 && b1 != 0){\n                n ^= bit_mask; // flip \n                c++; \n            }\n        }\n        \n        return (n == k ? c:-1);\n    }\n};\n```\n\n**Do upvote if it helps :)**
[]