C
#include <stdbool.h>
bool power_of_two(const int x) {
int power = 1;
while (power < x) power <<= 1;
return (power == x);
}
#include <stdbool.h>
bool power_of_two(const int x) {
if(x > 0 && (x & (x-1)) == 0) return true;
return false;
}
#include <stdbool.h>
bool power_of_two(const int x) {
return x && !(x - (x & -x));
}
#include <stdbool.h>
bool power_of_two(const int x) {
int n = x;
while( n > 1 ) {
if( n%2 != 0 ) return false;
n /= 2;
}
return n == 1;
}