用最简单的方法证明一个长整型数是2的倍数?
求解。

解决方案 »

  1.   

    number & 1 == 0 ?
      

  2.   


     long l=11;
           if((l&1)==0L){
               System.out.println(true);
           }
      

  3.   

    public class Test01 {    public static void main(String[] args) { 
            System.out.println(test(549755813888L));   // 2^39
        }
        
        public static boolean test(long n) {
            if(n < 0) {
                n = -n;
            }
            return Long.bitCount(n) == 1;
        }
    }