Java Number Power powerOf2Log2(int n)

Here you can find the source of powerOf2Log2(int n)

Description

power Of Log

License

Open Source License

Declaration

public static int powerOf2Log2(int n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int powerOf2Log2(int n) {
        assert isPowerOf2(n) : n + " is not a power of 2";
        for (int i = 0; i < 31; i++) {
            if ((n & 1) == 1) {
                return i;
            }/*from   w  ww. j ava2 s . c  o m*/
            n >>= 1;
        }
        return 0;
    }

    public static boolean isPowerOf2(int n) {
        return n == 0 || (n > 0 && (n & (n - 1)) == 0);
    }
}

Related

  1. powerLevelToDb0(double value)
  2. powerMean(final double p, final double[] x)
  3. powerMod(long base, long exp, long mod)
  4. powerOf(final int value, final int powerOf)
  5. powerOf10(int number)
  6. powerOf31(int n)
  7. powerOfN(Double v, int n)
  8. powerOfTen(int exp)
  9. powerOfTwo(final int i)