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

Answer Posted / anyone

//Revision for Ahmed Ihmeid answer:
//Operator % prototype: int % int

bool isPowerOf2(int num)
{
int x;

x = num % (int(ceil(sqrt(num)));

if( x == 0)
return true; //it is a power of 2
else
return false; //it is not
}

proof:
4 % 2 = 0
16 % 4 = 0
22 % 5 != 0

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is identifier in c?

549


What is a file descriptor in c?

566


Can include files be nested?

631


what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)

1932


Why we not create function inside function.

1751






what are bit fields? What is the use of bit fields in a structure declaration?

1501


write a program for the normal snake games find in most of the mobiles.

1789


What is the use of in c?

583


Write a program on swapping (100, 50)

640


What are 'near' and 'far' pointers?

623


What is character set?

687


difference between native and cross compilers

1673


Are global variables static in c?

679


Tell me when is a void pointer used?

650


write a program to input 10 strings and compare without using strcmp() function. If the character of one string matches with the characters of another string , sort them and make it a single string ??? example:- str1="Aakash" st2="Himanshu" str="Uday" output:- Aakashimanshuday (please post the answer as quickly as possible)

1629