C++ XOR solution with detail explain
Consider the 32-bit int number representing as follow:\n 0000 0000 0000 0000 0000 0000 0000 0101  ----> num\n 0111 1111 1111 1111 1111 1111 1111 1111  ----> mas
Consider the 32-bit int number representing as follow:\n* 0000 0000 0000 0000 0000 0000 0000 0101  **---->** **num**\n* 0111 1111 1111 1111 1111 1111 1111 1111  **---->** **mask** **---->** *key problem to calculate the mask*\n* 0111 1111 1111 1111 1111 1111 1111 1010  **---->** **complement = num XOR mask**\n\t\n```\n    int findComplement(int num) {\n\t    //First calculate the bit counts of num using log2()\n        unsigned int bits = floor(log2(num)) + 1;\n\t\t//Create a mask of pow(2, bits) - 1.\n\t\t//XOR the mask and the original num will get the complement number.\n        return ((unsigned int)(1 << bits) - 1) ^ num;\n    }\n```\n\nIf you like it, please upvote.
['Bit Manipulation', 'C', 'C++']