Leetcode 371 - Sum of two integers

Note:

• Not hard to come up with bit wise methods.
• The result must be a 32-bit integer. We init res as 0.
• Use prev to carry extra 1 from prev digit.
• For each digit, how should we add the result into res?
• Use curSum << i, it will right shift 1 and use | to add up with res.
• Should we care about negative numbers?
• No. Actually, when we do a >> 1 and a < 0, the left most will be filled with 0. If it’s a while loop, it would be a loop hole. But we only do this 32 times. So, it will def terminate.

Question:

Given two integers a and b, return the sum of the two integers without using the operators + and -.

Example:

Code: