Skip to content
Related Articles

Related Articles

Algorithms Quiz | Bit Algorithms | Question 4

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 28 Sep, 2018
Improve Article
Save Article

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

/* 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: (C)

Explanation: Please see

Quiz of this Question

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!