0 is not a power of 2

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Wed May 20 02:19:03 PDT 2015


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);
> }

Very nice


More information about the Digitalmars-d mailing list