[algogeeks] Adding Two numbers using bitwise operators only
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 unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Adding Two numbers using bitwise operators only
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 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 unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- 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 group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Adding Two numbers using bitwise operators only
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 PM, Sanjay Rajpal srn...@gmail.com wrote: 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 unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- 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 group at http://groups.google.com/group/algogeeks?hl=en. -- 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 group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Adding Two numbers using bitwise operators only
+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 group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Adding Two numbers using bitwise operators only
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 11:34 PM, priya ramesh love.for.programm...@gmail.com wrote: +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 group at http://groups.google.com/group/algogeeks?hl=en. -- With regards Puneet Chawla Computer Engineering Student NIT Kurukshetra -- 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 group at http://groups.google.com/group/algogeeks?hl=en.