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 the 8 primitive data types in java?

969


Write a program to calculate factorial in java?

949


What is formatted output in java?

893


How to sort array in descending order in java?

872


What is considered an anti pattern?

874


Can you give few examples of final classes defined in java api?

952


Name some OOPS Concepts in Java?

1016


Does sprintf allocate memory?

1036


What is integer parseint?

927


Can a java program have 2 main methods?

997


what is the swingutilities.invokelater(runnable) method for? : Java thread

988


Is char * a string?

931


How do I start learning java?

999


What is oop principle in java?

1043


What are the differences between abstract class and interface?

985