Power of Two
Given an integer, write a function to determine if it is a power of two.
/*************************************************************************
> File Name: LeetCode231.c
> Author: Juntaran
> Mail: Jacinthmail@gmail.com
> Created Time: 2016年05月10日 星期二 02时55分46秒
************************************************************************/ /************************************************************************* Power of Two Given an integer, write a function to determine if it is a power of two. ************************************************************************/ #include "stdio.h" int isPowerOfTwo(int n) {
int temp = (n> && !(n&(n-)));
return temp;
} int main()
{
int n = ;
int ret = isPowerOfTwo(n);
printf("%d\n",ret); n = ;
ret = isPowerOfTwo(n);
printf("%d\n",ret); return ;
}