How to add a code fix for infinite loop while adding two integers using bitwise operations
问题 Here is the original question. Here is the code for adding two integers using bitwise operations: def getSum(self, a, b): while (a & b): x = a & b y = a ^ b a = x << 1 b = y return a ^ b Though I know the reason why it goes into an infinite loop while adding a positive and negative integer, I need some help with coming up with the code-fix for this. 回答1: I am assuming that you have gone through the logic behind the infinite loop you are getting. logic Following is the behaviour of your