Quick actions

cmd+k|ctrl+k

Navigation

Languages

PowerOfTwo

Snippet info

Language

Java

Visibility

public

Author

pheker

Created

2018-03-14T03:16:07Z

Updated

2018-03-14T03:16:07Z

class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!");
        
        int c = 0;
        do{
            System.out.println("["+c+"]: "+calc(c));
        }while(c++ <10);
        
        
    }
    
    /**
     * 向上取2的次幂
     */
    public static int calc(int c){
        int n = c - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return n<1 ? 1:n+1;
    }
}
INFO