Java Number Round roundUpPower2(int v)

Here you can find the source of roundUpPower2(int v)

Description

round Up Power

License

Open Source License

Parameter

Parameter Description
v the value to be rounded

Return

the next power of two greater or equal to v

Declaration

public static final int roundUpPower2(int v) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w  w w  . java2  s  .  c  om
     * @param v the value to be rounded
     * @return the next power of two greater or equal to <i>v</i>
     */
    public static final int roundUpPower2(int v) {
        switch (Integer.bitCount(v)) {
        case 0:
            return (1);
        case 1:
            return (v);
        default:
            return (Integer.highestOneBit(v) << 1);
        }
    }
}

Related

  1. roundUpLong(long x, long blockSizePowerOf2)
  2. roundUpNumberByUsingMultipleValue(double number, double multiple)
  3. roundUpPOT(int value)
  4. roundUpPow2(int x)
  5. roundUpPower2(int i)
  6. roundUpTo(double in, double del)
  7. roundUpTo(int a, int quanta)
  8. roundUpTo(long i, long multiple)
  9. roundUpTo100(int n)