Given an integer n, return true if it is a power of two. Otherwise, return false.
An integer n is a power of two, if there exists an integer x such that n == 2x.
My code:
bool isPowerOfTwo(int n){
if (( n % 2 != 0 ) && ( n != 1 ) || ( n < 0 )) {
return false;
}
else {
float value = log2( n );
printf("%d", value);
int truncated = ( int ) value;
if ( value == truncated ) {
return true;
}
else {
return false;
}
}
}
It is not working with one submition test case valued 2147483646 , why ?
Thanks in advance