Function to find the given number is a power of 2 or not?

Answer Posted / abhishek sharma

unsigned int is_power_of_2(unsigned int x)
{
return (x != 0) && ((x & (x - 1)) == 0);
}

Is This Answer Correct ?    23 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how do you search data in a data file using random access method?

687


What is the time and space complexities of merge sort and when is it preferred over quick sort?

668


What is the difference between abs() and fabs() functions?

599


Explain how can I make sure that my program is the only one accessing a file?

614


What is %lu in c?

674






Is array name a pointer?

599


What are the types of i/o functions?

673


When a c file is executed there are many files that are automatically opened what are they files?

586


write a program to find out prime number using sieve case?

1631


What is a c token and types of c tokens?

584


What are pointers in C? Give an example where to illustrate their significance.

744


What is const and volatile in c?

561


Explain the use of bit fieild.

702


Is c procedural or functional?

580


What are categories used for in c?

560