Write a program to check an integer is a power of 2?
Answer:
Here, I am writing a small algorithm to check the power of 2. If a number is a power of 2, function return 1.
int CheckPowerOftwo (unsigned int x) { return ((x != 0) && !(x & (x - 1))); }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Answer:
Here, I am writing a small algorithm to check the power of 2. If a number is a power of 2, function return 1.
need an explanation for this answer? contact us directly to get an explanation for this answer