can we add two numbers without using arthematic operators?
if possible how?
Answer Posted / mohan
public static int addIterative(int a, int b){
while (b != 0){
int carry = (a & b) ; //CARRY is AND of two bits
a = a ^b; //SUM of two bits is A XOR B
b = carry << 1; //shifts carry to 1 bit to calculate sum
}
return a;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is private static class in java?
What is annotation in java?
What is an empirical question?
Difference between string, stringbuffer and stringbuilder?
What is java thread dump, how can we get java thread dump of a program?
What is classes in java?
What is a dot notation?
What are java packages?
What is the difference between final, finally and finalize()?
Enlist few advantages of inheritance?
Difference between throw and throws?
explain different ways of using thread? : Java thread
what is the messsage u r going to get from an objectoriented programing?
What is string in java? String is a data type?
What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?