Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

what is the significance of listiterator in java?

1027


What is string immutability?

1025


Define how objects are stored in java?

992


What is sortedmap in java?

976


What are the advantages and disadvantages of object cloning?

1040


What happens if an exception is not handled in a program?

1046


How many types of methods are there?

972


Why are pointers not secure?

973


State some situations where exceptions may arise in java?

1002


What is exception propagation?

1068


What is the difference between throw and throws in java?

1028


Explain about procedural programming language or structured programming language and its features?

1028


What is an object in java and how is it created?

1004


When should we create our own custom exception classes?

960


How can we run a java program without making any object?

982