# addition of 2 nos without using arithmetic operators



## techian_cool (Sep 7, 2007)

hi people...
i would like to know if there is any way to add two numbers without using arithmetic operators... if so could you tell me.. i need the coding in c++.
thanks a lot.
techian_cool


----------



## Shadow2531 (Apr 30, 2001)

You could make a function to do it with the &, ^ and << operators and a loop. (It'd be around 7 lines of code.)

Try searching the net for binary adders or adders or half-adders or full adders or possibly even logic gate adders.


----------



## Shadow2531 (Apr 30, 2001)

This might give a hint:

```
#include <iostream>
using namespace std;

int add(const int a, const int b) {
    int sum = a ^ b;
    int carry = a & b;
    int temp;
    while (carry != "fill in the blank") {
        carry <<= "fill in the blank";
        temp = "fill in the blank";
        carry &= "fill in the blank";
        sum = "fill in the blank";
    }
    return sum;
}

int main() {
    cout << add(5, 4) << "\n";
}
```


----------



## techian_cool (Sep 7, 2007)

thanks... i'll try


----------

