You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The bitwise add 2 integers solution will hit infinite loop for negative integers. The carry will keep increasing if the bit length is not bounded.
Proposed solution:
defsum_two(self,a,b):
#max bit length, change to 32 for 32bitmax_positive=2**64min_negative=-2**64whileb!=0:
ifb==max_positive:
returna^min_negativea,b=a^b,(a&b)<<1returna
The text was updated successfully, but these errors were encountered:
The bitwise add 2 integers solution will hit infinite loop for negative integers. The carry will keep increasing if the bit length is not bounded.
Proposed solution:
The text was updated successfully, but these errors were encountered: