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 the difference between heap memory and stack memory?
Why do we need hashset in java?
Can an arraylist be empty?
What is a dynamic array in java?
What is 32 bit float?
Can we override private method?
What is vector capacity in java?
List implementations of list interface?
What are java packages?
Explain throw keyword in java?
Explain about data types?
Can we increase size of array?
Difference between == and .equals() ?
Difference between a class and an object?
What is integer valueof?