代码内容:
int aplusb(int a, int b) {
// write your code here
int step1 = a ^ b;
int step2 = a & b;
while(step2)
{
int c = step2 << 1;
int d = step1;
step1 = c ^ d;
step2 = c & d;
}
return step1;
}
了解位运算的相关内容
a ^ b = 位数相
1 ^ 1 = 0
1 ^0 = 1
0 ^ 1 = 1
0 ^ 0 = 0
a & b = 位数进阶
1 & 1 = 1
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
当位数无法进阶时代表加完