DEV Community

Discussion on: Power of 2, solving a google interview question. Playing with bits.

Collapse
 
namhle profile image
Nam Hoang Le • Edited

Hi,
It should be
const pow2 = n => n & ((n & (n-1)) == 0)
to avoid return true for zero.
Btw, thanks for sharing!

Collapse
 
akhilpokle profile image
Akhil

Thanks for pointing out and reading my article :), I made a mistake, the range is between 1 -> 2^31-1, my bad