面试题47 不用+-*/ 做加法

int sum(int a, int b){
    int carry = 1;
    int res = 0 ;
    while(carry != 0){
        res = a^b;
        carry = (a&b)<<1;
        a = res;
        b = carry;
    }
    return res;
}

 

posted @ 2013-09-21 10:16  冰点猎手  阅读(131)  评论(0编辑  收藏  举报