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;
}
纯模拟,记住就行
Sum of Two Integers计算机如何实现两个数相加
最新推荐文章于 2020-06-29 13:43:43 发布