Best Python solution with easy explanation | Bit manipulation
Assuming you understood the bit manipulation method in other languages.\n2. The solution in Python is different than other languages because in Python it consid
1. Assuming you understood the bit manipulation method in other languages.\n2. The solution in Python is different than other languages because in Python it considers the unlimited length of integers whereas in other languages integers has fixed length of 32-bit. \n3. If we perform the normal bit manipulation solution in python then the loop runs for infinite times as integers are not fixed to 32-bit. To avoid this in python we use a MASK 0xffffffff to keep the integer in 32-bits.\n4. At last we have conditions to return the value because especially for negative integers we have to first calculate the two\'s complement of the returning number. But only ~a will flip infinite bits of a and hence we have  limit it in 32-bit using MASK. Thus we xor a with mask and finally return ~(a^MASK).\n```\nclass Solution:\n    def getSum(self, a: int, b: int) -> int:\n        MASK = 0xffffffff\n        while b:\n            carry = a&b\n            a = (a ^ b) & MASK\n            b = (carry << 1) & MASK\n            \n        if (a>>31) & 1:\n            return ~(a^MASK)\n        return a\n```
['Bit Manipulation', 'Python']