Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to add two numbers  RSS feed

 
nivas yl
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all

How to add two numbers using Bit wise operators.
 
Brian Cole
Author
Ranch Hand
Posts: 959
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sreenivas yelgam:
How to add two numbers using Bit wise operators.


A better question is why would you want to?

It makes a good homework question because it requires understanding of how both bitwise operators and addition works, but otherwise there's not much point.

Here's a somewhat silly implementation but I think you'll probably have study it and understand it before it will do you much good. It might not even be obvious at first glance that the recursive calls are guaranteed to terminate.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!