int addThroughBit1(int num1,int num2) { if(num2==0) return num1; int tmp,carry; tmp=num1^num2; carry=(num1&num2)<<1; return addThroughBit1(tmp,carry); }
int addThroughBit2(int num1,int num2) { int tmp=num1,carry=num2; int sum; while(carry!=0) { sum=tmp^carry; carry=(tmp&carry)<<1; tmp=sum; } return tmp; }
原文:http://www.cnblogs.com/yxwkf/p/3900873.html