Java Ceil ceilPowerOf2(int x)

Here you can find the source of ceilPowerOf2(int x)

Description

Rounds up the value to the nearest higher power^2 value.

License

Open Source License

Parameter

Parameter Description
x a parameter

Return

power^2 value

Declaration

public static final int ceilPowerOf2(int x) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w w  w.ja  v a  2s  . c om*/
     * Rounds up the value to the nearest higher power^2 value.
     *
     * @param x
     * @return power^2 value
     */
    public static final int ceilPowerOf2(int x) {
        int pow2 = 1;
        while (pow2 < x) {
            pow2 <<= 1;
        }
        return pow2;
    }
}

Related

  1. ceilMultiple(float source, float multiple)
  2. ceilPositive(float x)
  3. ceilPoT(int arg)
  4. ceilPow2(int v)
  5. ceilPowerOf2(final long x)
  6. ceilPowerOf2Bits(final long x)
  7. ceilPrime(long p)
  8. ceilSec(long milli)
  9. ceilToBase(int number, int base)