C++ || 100% faster || With explanation
If you ever confront these type of problems, then bitwise manipulation will always be the key to it.\n\nSo, the solution is relatively simple, we loop until the
If you ever confront these type of problems, then bitwise manipulation will always be the key to it.\n\nSo, the solution is relatively simple, we loop until the second integer \'b\' (vice versa) gets to 0.\nWe use c variable (for carry condition) to get the common bits between a and b (using & operator). \nCommon bit( 0,0 and 1,1) will have carry 0 and 1 respectively. It is set to unsigned as we have negative number cases as well.\n\nUsing XOR operator, we will be doing our main operation. ^ this breaks down decimal into binary and checks if we have different values. If 0 and 1, 1 and 0 then it simply adds it to 1 . If 0 0 it does nothing. If 1 1, it produces a carry for the next bit and makes current bit sum as 0. I would recommend reading about XOR and & operators before advancing to this problem.\n\nIf we have carry condition and we need to create new bit we add 1 to sum. (Eg. 100 and 111 would be 011, so we need to add 1 at front to get our desired answer).\n\nTo take care about termination of the loop we will pass our carry into left shift operator and store that value into b. To put it simply, b becomes zero when carry becomes zero.![image](https://assets.leetcode.com/users/images/1ac04624-3829-4631-93e6-508ed47e4c9e_1628830332.97185.jpeg)\nHere\'s an example with a=2, b=3 where sum is 5.\n\nI hope you understood the solution, if you liked it please do upvote the post :)\n\n```\nint getSum(int a, int b) {\n        while(b) {\n            unsigned c = a&b;\n            a ^= b;\n            b = c << 1;\n        }\n        return a;\n}\n```
['Bit Manipulation', 'C']