• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Algorithms Quiz | Bit Algorithms | Question 4

Consider the following code snippet for checking whether a number is power of 2 or not. 

C
/* Incorrect function to check if x is power of 2*/
bool isPowerOfTwo (unsigned int x) 
{ 
  return (!(x&(x-1))); 
} 

What is wrong with above function?

(A)

It does reverse of what is required

(B)

It works perfectly fine for all values of x.

(C)

It does not work for x = 0

(D)

It does not work for x = 1

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments