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

What is a volatile keyword in c?

638


What is variable and explain rules to declare variable in c?

556


Can you assign a different address to an array tag?

702


Create a structure to specify data on students given below: Roll number, Name, Department, Course, Year of joining Assume that there are not more than 450 students in the college. 1.write a function to print names of all students who joined in a particular year 2.write a function to print the data of a student whose roll number is given

2520


How do you define a function?

583






Disadvantages of C language.

663


Which control loop is recommended if you have to execute set of statements for fixed number of times?

811


How can a program be made to print the line number where an error occurs?

652


When c language was developed?

642


What is the use of typedef in c?

588


What is array of structure in c?

598


What type is sizeof?

587


What is sizeof in c?

572


Who is the founder of c language?

687


Why is c called "mother" language?

858