[algogeeks] Adding Two numbers using bitwise operators only

2011-08-20 Thread Sanjay Rajpal
Hey frnds, I am stuck in a problem of adding two numbers using bitwise operators only. An explanation is required. Sanju :) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To

Re: [algogeeks] Adding Two numbers using bitwise operators only

2011-08-20 Thread sagar pareek
Refer half adder :) *sum = a ^ b; carry = a b; while (carry != 0) { carry = 1; a = sum; b = carry; sum = a ^ b; carry = a b; }* On Sat, Aug 20, 2011 at 9:32 PM, Sanjay Rajpal srn...@gmail.com wrote: Hey frnds, I am stuck in a problem of adding two numbers using bitwise operators only. An

Re: [algogeeks] Adding Two numbers using bitwise operators only

2011-08-20 Thread Sanjay Rajpal
Could you post some link here ? Sanju :) On Sat, Aug 20, 2011 at 9:08 AM, sagar pareek sagarpar...@gmail.com wrote: Refer half adder :) *sum = a ^ b; carry = a b; while (carry != 0) { carry = 1; a = sum; b = carry; sum = a ^ b; carry = a b; }* On Sat, Aug 20, 2011 at 9:32

Re: [algogeeks] Adding Two numbers using bitwise operators only

2011-08-20 Thread priya ramesh
+1 sagar! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this

Re: [algogeeks] Adding Two numbers using bitwise operators only

2011-08-20 Thread Puneet Chawla
For subtraction we can use the same add function int add(int a, int b) { while (a) { a = (a b) 1; b = a^b; } return b; } int sub(int a, int b) // add a with b's 2's complement. { return (add(a, add(~b, 1))); } On Sat, Aug 20, 2011 at