0 is not a power of 2
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 19 05:41:12 PDT 2015
On 5/19/15 1:37 AM, H. S. Teoh via Digitalmars-d wrote:
> On Mon, May 18, 2015 at 10:16:47PM -0700, Andrei Alexandrescu via Digitalmars-d wrote:
> [...]
>> bool isPowerOf2(uint x)
>> {
>> return (x & (x - 1) | !x) == 0;
>> }
> [...]
>
> Are you sure that's correct? Doesn't that return true for all non-zero
> numbers?
It's bitwise or, not logic or.
-Steve
More information about the Digitalmars-d
mailing list