Get int next Power Of 2 - Android java.lang

Android examples for java.lang:Integer

Description

Get int next Power Of 2

Demo Code



public class Main{


    public static int nextPowerOf2(int n) {
        n -= 1;//w  w w. j a  v a2s  . co  m
        n |= n >>> 16;
        n |= n >>> 8;
        n |= n >>> 4;
        n |= n >>> 2;
        n |= n >>> 1;
        return n + 1;
    }

}

Related Tutorials