• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding number without arthemetic operator  RSS feed

 
Arun Giridhar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I want to know how to add numbers without arthemetic operator , possible hint would be fine.

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the motivation behind the question? Sounds like one of those "I was asked this in an interview" trick questions.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the sort of thing you should do as a party trick and not for anything else.

Start by asking what arithmetic operator means.
 
Liutauras Vilda
Sheriff
Posts: 4926
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun,

1. You can use BigInteger class and then apply "add" method. Since you and whoever asks you "don't know" the implementation details of BigInteger class, you can assume you're not using arithmetic operator (I could guess that it is not what was expected by the person who asked you that)
2. Other methodology could be using bitwise operators (&, ^) and binary shifting operator (this is likely what was expected)

Once again, what guys already told you, you should supply a bit more information, so would be possible to understand the intent of all this, and as Campbell Ritchie clearly explained you, this is not what you should be doing practically.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as you can be sure that the add method doesn't count as an arithmetic operator.
Hold your heart on your hand and tell me that i << 3 is not an arithmetic operation when it is equivalent to i * 8.
 
Liutauras Vilda
Sheriff
Posts: 4926
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took descriptions of operators from here. With all respect Campbell, I wouldn't like, but I could argue on your second statement
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case << & | >> >>> and ^ are permitted.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!