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

Find if a number is power of two or not?

Answer Posted / om

int f(int num)
{

if(( num>0) && (!(num & (num-1))) )
return 1;
else
return 0;
}
// f(16)...... 16 & 15 = 10000 & 01111 =00000
f(4) ...... 4 & 3 =0100 & 0111 =0000

f(11).......11 & 10 = 1011 & 1010 = 1010 so not...
f(12).......12 & 11 = 1100 & 1011 = 1000 so not...

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Are pointers really faster than arrays?

969


Why do some versions of toupper act strangely if given an upper-case letter?

1040


How can I find the modification date and time of a file?

1030


How can I find out if there are characters available for reading?

1058


What is the use of static variable in c?

1046


What are the __date__ and __time__ preprocessor commands?

1044


Why is structure important for a child?

1050


How can you convert integers to binary or hexadecimal?

983


What is scope and lifetime of a variable in c?

992


How many types of sorting are there in c?

1013


Is c programming hard?

973


What is the use of clrscr?

1056


Explain the difference between getch() and getche() in c?

941


How do I use strcmp?

1027


What is the use of header files?

1060