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 are namespaces in java?

1027


Can we override compareto method?

944


How do you declare an array in java?

1047


What is the difference between normal report & matrix report?

1100


What is arguments in java?

997


Explain java coding standards for methods?

1034


What is a finally block? Is there a case when finally will not execute?

1061


How many threads can java run?

1107


Explain the importance of finally over return statement?

1037


What is empty string literal in java?

1052


What is ascii code?

1253


What 5 doubled?

980


What is super in java?

987


What is queue in java?

1138


How to find the largest value from the given array.

1007