Sum of Two Integers计算机如何实现两个数相加

来源:互联网 发布:杀破狼js mp3下载 编辑:程序博客网 时间:2024/06/05 12:40
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;}
纯模拟,记住就行
0 0