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...

How to add two numbers with out using Arithmetic , union
operators in java....?

But we can use bitwise operators... but how...?

Answer Posted / midhula

public int addtwo(int a,int b)
{
if(b==0)
return a;

int sum = a ^ b; // ^ will be 1 if both operands are
//different otherwise 0.
int carry = (a & b) <<1; //& will be 1 if both operands are
//1 otherwise 0

return addtwo(sum,carry);
}

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is append in java?

1171


What is type safety in java?

956


How to change the priority of thread or how to set priority of thread?

1031


What is the difference between a factory and abstract factory pattern?

1148


What is var keyword ?

1191


What does this mean java?

1114


Which of the classes will have more memory allocated?

977


Lowest Common ancestor in a Binary Search Tree and Binary Tree.

933


What do you mean by local variable and instance variable?

958


Is string an object?

1122


What is int lol?

1142


Where import statement is used in a java program?

1134


How do you use find and replace?

960


Is java free for businesses?

1073


What is <> used for in java?

1119