News for hackers. Stuff that matters.
Re:Write A Function To Determine If A Number Is A Power Of 2 by vilya on Monday October 18, 2010 @01:00PM (#1804223)
Using gcc compiler intrinsics (which should compile to a single assembly instruction where possible):

  bool isPowerOf2(unsigned int n) {
    return __builtin_popcount(n) == 1;
  }

There are no comments on this comment yet.