bool isPowerOf2(uint x)
{
return (x & -x) > (x - 1);
}
I think you can make the over/underflow at zero work in your
favor:
- Re: 0 is not a power of 2 deadalnix via Digitalmars-d
- Re: 0 is not a power of 2 Steven Schveighoffer via Digitalmars-d
- Re: 0 is not a power o... deadalnix via Digitalmars-d
- Re: 0 is not a pow... Steven Schveighoffer via Digitalmars-d
- Re: 0 is not a... deadalnix via Digitalmars-d
- Re: 0 is ... Steven Schveighoffer via Digitalmars-d
- Re: 0 is not a power of 2 Brian Schott via Digitalmars-d
- Re: 0 is not a power o... deadalnix via Digitalmars-d
- Re: 0 is not a power of 2 Matthias Bentrup via Digitalmars-d
- Re: 0 is not a power of 2 John Colvin via Digitalmars-d
- Re: 0 is not a power o... Temtaime via Digitalmars-d
- Re: 0 is not a pow... via Digitalmars-d
- Re: 0 is not a power of 2 Andrei Alexandrescu via Digitalmars-d
- Re: 0 is not a power of 2 Dominikus Dittes Scherkl via Digitalmars-d
- Re: 0 is not a power of 2 Jay Norwood via Digitalmars-d
- Re: 0 is not a power of 2 Jay Norwood via Digitalmars-d
