Over a million developers have joined DZone.

IsPowerOf2 In C

·

bool isPowerOf2(unsigned int n)
{
    return n == 1 || (n & (n-1)) == 0;
}


CPU's inner integer representation must be two's complement.
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}