// 利用位运算
int get_sum( int a, int b )
{
// Iterate till there is no carry
while ( 0 != b )
{
// carry now contains common set bits of a and b
int carry = a & b;
// Sum of bits of a and b where at least one of the bits is not set
a = a ^ b;
// Carry is shifted by one so that adding it to a gives the required sum
b = carry << 1;
}
return a;
}
不用+的加法
最新推荐文章于 2023-08-18 10:12:03 发布