✔️ [Python3] BITWISE OPERATORS •͡˘㇁•͡˘, Explained
The idea is to shift all bits of the given integer to the right in the loop until it turns into 0. Every time we do a shift we use a mask to check what is in th
The idea is to shift all bits of the given integer to the right in the loop until it turns into `0`. Every time we do a shift we use a mask to check what is in the right-most bit of the number. If bit is `0` we add `2**n` to the result where `n` is the current number of shifts. Example:\n```\nn=0, num=1010, bit=0 => res += 2**0\nn=1, num=0101, bit=1 => res += 0\nn=2, num=0010, bit=0 => res += 2**2\nn=3, num=0001, bit=1 => res += 0\n     num=0000 => break the loop\n```\n\nRuntime: 24 ms, faster than **94.85%** of Python3 online submissions for Number Complement.\nMemory Usage: 14.2 MB, less than **68.47%** of Python3 online submissions for Number Complement.\n\n```\nclass Solution:\n    def findComplement(self, num: int) -> int:\n        res, n = 0, 0\n        while num:\n            if not num & 1:\n                res += 2**n\n                \n            num >>= 1\n            n += 1\n        \n        return res\n```
['Bit Manipulation', 'Python3']