# 面试题65

写一个函数，求两个整数之和，要求在函数体内不得使用 “+”、“-”、“\*”、“/” 四则运算符号。

```
示例:

输入: a = 1, b = 1
输出: 2
```

## 提示：

* a, b 均可能是负数或 0
* 结果不会溢出 32 位整数

## Solutions

1. **straight forward**
2. reference: [https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/solution/jin-zhi-tao-wa-ru-he-yong-wei-yun-suan-wan-cheng-j/](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/solution/jin-zhi-tao-wa-ru-he-yong-wei-yun-suan-wan-cheng-j/)
3. `011 + 11 = 11 ^ 11 + ((11 & 11) << 1) = 000 + 110 = 110`

```cpp
class Solution {
public:
    int add(int a, int b) {
        while (b) {
            int sum = a ^ b;
            b = (unsigned int)(a & b) << 1;
            a = sum;
        }

        return a;
    }
};
```
