异或其实是无进位加法,与取进位。
int getSum(int a, int b) { int ret = a ^ b; int carry = a & b; while (carry) { carry = carry << 1; int temp = carry; carry = carry & ret; ret = ret ^ temp; } return ret; }
本文共 321 字,大约阅读时间需要 1 分钟。
异或其实是无进位加法,与取进位。
int getSum(int a, int b) { int ret = a ^ b; int carry = a & b; while (carry) { carry = carry << 1; int temp = carry; carry = carry & ret; ret = ret ^ temp; } return ret; }
转载于:https://www.cnblogs.com/willaty/p/8436515.html