Forums Register Login

Adding number without arthemetic operator

+Pie Number of slices to send: Send
Hello,

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

Thank you
+Pie Number of slices to send: Send
What's the motivation behind the question? Sounds like one of those "I was asked this in an interview" trick questions.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
I took descriptions of operators from here. With all respect Campbell, I wouldn't like, but I could argue on your second statement
1
+Pie Number of slices to send: Send
In that case << & | >> >>> and ^ are permitted.
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 449 times.
Similar Threads
Instance count
Need an event in a client program
footer in itext how
java.lang.NoClass DefFoundError: while resolving class
Total Newbie question (adding items to TabbedPanes)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:01:37.