Java Number Round roundUpToPowerOf2(int number)

Here you can find the source of roundUpToPowerOf2(int number)

Description

round Up To Power Of

License

Apache License

Declaration

public static int roundUpToPowerOf2(int number) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static int roundUpToPowerOf2(int number) {
        // assert number >= 0 : "number must be non-negative";
        int rounded = number >= Integer.MAX_VALUE ? Integer.MAX_VALUE
                : (rounded = Integer.highestOneBit(number)) != 0
                        ? (Integer.bitCount(number) > 1) ? rounded << 1 : rounded
                        : 1;//from w  w  w .j  a  va2 s. c om
        return rounded;
    }
}

Related

  1. roundUpTo8(long val)
  2. roundUpToMultiple(long val, int factor)
  3. roundUpToNearest(double number, double nearest)
  4. roundUpToNearestEightBytes(long result)
  5. roundUpToNearestPowerOfTwoIfGreaterThanZero(final int value)
  6. roundUpToPowerOf2(long val)
  7. roundUpToPowerOf2Factor(long val, long factor)
  8. roundUpToPowerOfTwo(int i)
  9. roundUpToPowerOfTwo(int p_151236_0_)