On Tuesday, 19 May 2015 at 20:46:09 UTC, Matthias Bentrup wrote:
I think you can make the over/underflow at zero work in your favor:

bool isPowerOf2(uint x)
{
  return (x & -x) > (x - 1);
}

The cool thing is that also the over/underflow of "-" at 0x8000_0000 works. But that is really a weird calculation! Wouldn't pass any Polyspace or other code checker tool and need some special comments on why it works...

Reply via email to