Q:

Is there a trick to testing if a non-specific bit is set anywhere in an int? 

I want to test whether any single bit is set in a C int.  I don't care which bit it is. 
Equivalent to
if (1 == count_bits (n))

I'm curious if there is a non-looping algorithm for this which does not require special hardware support. 

A:

If only one bit is set, then the number is a power of two.      
unsigned int IsPowerOfTwoNoLoop(unsigned int input)
{
    unsigned int temp = input;
    if(0 == input)
    {
      return 0;
    }
    temp -= 1;
    /*Example of the logic:*/
    /*  0100 (4 DEC) - 1 = 0011
        0011 & 0100 = 0000 
    */
    if (temp & input) /* if not zero - not pow of two */
    {
        printf("%u Is NOT the power of two ! \n", input);
        return 0;
    }

    printf("%u Is the power of two ! \n", input);
    return 1;
}

