public class Test {
    public static void main(String[] args) {

        System.out.println(isPow(4));

    }

    public static boolean isPow(int number){
        return (number&number-1) == 0;
    }
}

 

高位都是1 低位都是0 

-1后 所有位都是1 高位为0

与后为0

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2021-12-09
  • 2021-07-23
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案