Created
July 22, 2017 05:07
-
-
Save zhangzhiqiangcs/58c74da99b7656b38e471c4faa10a593 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int getSum(int a, int b) { | |
int sum = a; | |
while (b != 0) | |
{ | |
sum = a ^ b;//calculate sum of a and b without thinking the carry | |
b = (a & b) << 1;//calculate the carry | |
a = sum;//add sum(without carry) and carry | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment