Why if (n & -n) == n then n is a power of 2?

后端 未结 0 1793
北海茫月
北海茫月 2020-12-22 16:02

Line 294 of java.util.Random source says

if ((n & -n) == n) // i.e., n is a power of 2
    // rest of the code

Why is this?

相关标签:
回答
  • 消灭零回复
提交回复
热议问题