```
public bool IsPowerOfTwo(int n)
{
if (n <= 0) return false;
int temp = n;
int oneBitCount = 0;
do
{
oneBitCount += 1 & temp;
temp = temp >> 1;
}
while (temp != 0);
return (oneBitCount <= 1);
}
```