Solution By Dare2Solve | Detailed Explanation | Clean Code
Explanation []\nauthorslog.com/blog/X5ylrr9UTV\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n    int getSum(int a, int b) {\n        while (b != 0) {\n       
```Explanation []\nauthorslog.com/blog/X5ylrr9UTV\n```\n# Code\n\n```cpp []\nclass Solution {\npublic:\n    int getSum(int a, int b) {\n        while (b != 0) {\n            int tmp = (a & b) << 1; // carry calculation\n            a = a ^ b; // sum without carry\n            b = tmp; // carry shifted left\n        }\n        return a;\n    }\n};\n```\n\n```python []\nclass Solution:\n    def getSum(self, a: int, b: int) -> int:\n        MAX = 0x7FFFFFFF  # Maximum positive int (32-bit)\n        MASK = 0xFFFFFFFF  # Mask to get last 32 bits\n        \n        while b != 0:\n            tmp = (a & b) << 1  # carry calculation\n            a = (a ^ b) & MASK  # sum without carry (limit to 32 bits)\n            b = tmp & MASK  # carry shifted left (limit to 32 bits)\n        \n        # If a is greater than MAX, it\'s a negative number in 32-bit representation\n        return a if a <= MAX else ~(a ^ MASK)\n```\n\n```java []\nclass Solution {\n    public int getSum(int a, int b) {\n        while (b != 0) {\n            int tmp = (a & b) << 1; // carry calculation\n            a = a ^ b; // sum without carry\n            b = tmp; // carry shifted left\n        }\n        return a;\n    }\n}\n```\n\n```javascript []\nvar getSum = function(a, b) {\n    while(b !=0)\n    {\n        let tmp = (a& b) <<1;\n        a = a^b;\n        b = tmp;\n    }\n    return a;\n\n};\n```
['Math', 'Bit Manipulation', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']