C++ FAQ Celebrating Twenty-One Years of the C++ FAQ!!!
(Click here for a personal note from Marshall Cline.)
Section 26:
[26.12] How can I tell if an integer is a power of two without looping?
inline bool isPowerOf2(int i)
{
  return i > 0 && (i & (i - 1)) == 0;
}