+ 4

Is it possible to add numbers without using "+"?

21st Apr 2017, 1:52 PM
Pratham
Pratham - avatar
2 Réponses
+ 18
cout << 1-(-1); // outputs 2.
21st Apr 2017, 1:54 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
You can also do it using only bitwise operations like this: int add(int a, int b){ while(b){ int t = a ^ b; b = (a & b) << 1; a = t; } return a; } ^ is binary XOR, & is binary AND and << is binary left shift.
21st Apr 2017, 3:28 PM
Robobrine
Robobrine - avatar