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

后端 未结 0 1336
悲&欢浪女
悲&欢浪女 2020-12-22 16:18

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?

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