428,838 Members | 2,222 Online
Need help? Post your question and get tips & solutions from a community of 428,838 IT Pros & Developers. It's quick & easy.

# How to add two numbers without using the plus operator?

 P: n/a How to add two numbers without using the plus operator? Jun 6 '06 #1
16 Replies

 P: n/a co******@gmail.com wrote: How to add two numbers without using the plus operator? a-(-b) Jun 6 '06 #2

 P: n/a aahhh!!!! not this way. using bitwise operators .. Markus Schoder wrote: co******@gmail.com wrote: How to add two numbers without using the plus operator? a-(-b) Jun 6 '06 #3

 P: n/a co******@gmail.com wrote: aahhh!!!! not this way. using bitwise operators .. Markus Schoder wrote: co******@gmail.com wrote: How to add two numbers without using the plus operator? a-(-b) Give us your instructor's email address, and we'll send the answer directly to him. Jun 6 '06 #4

 P: n/a What are you trying to prove by this?? If u know its answer then post here...or else go to hell. red floyd wrote: co******@gmail.com wrote: aahhh!!!! not this way. using bitwise operators .. Markus Schoder wrote: co******@gmail.com wrote: How to add two numbers without using the plus operator? a-(-b) Give us your instructor's email address, and we'll send the answer directly to him. Jun 6 '06 #6

 P: n/a On 6 Jun 2006 16:16:46 -0700, "co******@gmail.com" wrote: red floyd wrote: co******@gmail.com wrote: > aahhh!!!! > not this way. > using bitwise operators .. > > Markus Schoder wrote: >> co******@gmail.com wrote: >>> How to add two numbers without using the plus operator? >> a-(-b) > Give us your instructor's email address, and we'll send the answer directly to him.What are you trying to prove by this??If u know its answer then post here...or else go to hell. You are asking us for help. It pays to be polite if you are asking for help. If you are not polite we may decide that we don't want to help you. All you need to do is to create a successor() function and use the Peano axioms. rossum Jun 6 '06 #7

 P: n/a In article <11**********************@u72g2000cwu.googlegroups .com>, "co******@gmail.com" wrote: How to add two numbers without using the plus operator? Why would you want to? Jun 7 '06 #8

 P: n/a In article <1149631877.720828.165900 @u72g2000cwu.googlegroups.com>, co******@gmail.com says... How to add two numbers without using the plus operator? Just about any digital design book should have the circuitry for a half-adder and a full-adder. Each bit of result is the XOR of its inputs, and each carry bit is the OR of its inputs. -- Later, Jerry. The universe is a figment of its own imagination. Jun 7 '06 #9

 P: n/a In article <1149631877.720828.165900 @u72g2000cwu.googlegroups.com>, co******@gmail.com says... How to add two numbers without using the plus operator? Just about any digital design book should have the circuitry for a half-adder and a full-adder. Each bit of result is the XOR of its inputs, and each carry bit is a one if two or more of the input bits are one. -- Later, Jerry. The universe is a figment of its own imagination. Jun 7 '06 #10

 P: n/a Daniel T. wrote: In article <11**********************@u72g2000cwu.googlegroups .com>, "co******@gmail.com" wrote: How to add two numbers without using the plus operator? Why would you want to? Because that's his homework assignment. He already was given an answer a - (-b), and bitched at us that it wasn't what he wanted. Jun 7 '06 #11

 P: n/a co******@gmail.com wrote: What are you trying to prove by this?? If u know its answer then post here...or else go to hell. red floyd wrote: Give us your instructor's email address, and we'll send the answer directly to him. Hmmmm. 1. Homework cheater. 2. Top-poster. 3. Uses "u", 4. Rude. I think that adds up to *plonk*. Brian Jun 7 '06 #12

 P: n/a Markus Schoder wrote: co******@gmail.com wrote:How to add two numbers without using the plus operator? a-(-b) Or (-a-b)*(-1) Best regards Martin Jørgensen -- --------------------------------------------------------------------------- Home of Martin Jørgensen - http://www.martinjoergensen.dk Jun 7 '06 #13

 P: n/a Markus Schoder wrote: co******@gmail.com wrote: How to add two numbers without using the plus operator? a-(-b) Doesn't work if they are ints and b is INT_MIN and INT_MIN < -INT_MAX. Another option: a += b; // use a a -= b; Jun 8 '06 #14

 P: n/a On 6 Jun 2006 15:11:17 -0700, "co******@gmail.com" wrote: How to add two numbers without using the plus operator? This will not, compile, take the ideas: while (carry!=0) { sum=a xor carry; carry=(a and carry) to the left one bit; } You must find what to put in sum and carry initiallly. This downgrades the homework a couple of levels. If you don't understand it, read the message from presenaama. Regards, and do your homework! Zara Jun 8 '06 #15

 P: n/a Old Wolf wrote: Markus Schoder wrote: co******@gmail.com wrote: How to add two numbers without using the plus operator? a-(-b) Doesn't work if they are ints and b is INT_MIN and INT_MIN < -INT_MAX. Yes, I guess the standard labels this as undefined behaviour. In reality it will work even for this corner case just fine with every existing implementation. Jun 8 '06 #16

 P: n/a Markus Schoder wrote: Old Wolf wrote: Markus Schoder wrote: co******@gmail.com wrote: How to add two numbers without using the plus operator? a-(-b) Doesn't work if they are ints and b is INT_MIN and INT_MIN < -INT_MAX. Yes, I guess the standard labels this as undefined behaviour. In reality it will work even for this corner case just fine with every existing implementation. Did you try it on all of them? What about future implementations? I have heard of current ones that trap on integer overflow. Jun 8 '06 #17

### This discussion thread is closed

Replies have been disabled for this discussion.