How to add two numbers without using the plus operator?

There are many ways. You could do how you do it on paper. You could use the property x + y = (x-1)+(y+1).

Well i want to know the method using bitwise operators.
I don't know exaclty how to do it.
But I can tell you a little bit, so that if you know you can help me.

It's like...
SUM = a XOR b
CARRY= a AND b

Here is one idea using the post increment operator:

int a, b;

cout << "\nEnter first number: ";
cin >> a;

cout << "\nEnter second number: ";
cin >> b;

for (int i = 0; i < a; i++)

     b++;

cout << "\nThe answer is: " << b;

Thanks clinton
but i wanted to know the answer using bitwise operator.
Is there anyone listening...???

Here is one idea using the post increment operator:

int a, b;

cout << "\nEnter first number: ";
cin >> a;

cout << "\nEnter second number: ";
cin >> b;

for (int i = 0; i < a; i++)

     b++;

cout << "\nThe answer is: " << b;

You know how the bitwise operators work, right? You know how to add two numbers in binary, or can look that up, right? Flex your creativity muscles, or you'll continue to be unable to solve your own problems.

Member Avatar for iamthwee

There are loads of examples on the web showing you how to add numbers, in your case, binary numbers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.