Java Ceil ceilingPowerOfTwo(int value)

Here you can find the source of ceilingPowerOfTwo(int value)

Description

Returns the smallest power of two number that is greater than or equal to value .

License

LGPL

Parameter

Parameter Description
value reference number

Return

smallest power of two number

Declaration

public static int ceilingPowerOfTwo(int value) 

Method Source Code

//package com.java2s;
/*/*from   w  w w.ja v a2s . com*/
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
 */

public class Main {
    /**
     * Returns the smallest power of two number that is greater than or equal to {@code value}.
     *
     * @param value reference number
     * @return smallest power of two number
     */
    public static int ceilingPowerOfTwo(int value) {
        return 1 << -Integer.numberOfLeadingZeros(value - 1);
    }
}

Related

  1. ceilingNextPowerOfTwo(final int x)
  2. ceilingPow2(int n)
  3. ceilingPowerOf2(final int n)
  4. ceilingPowerOf2(int n)
  5. ceilingPowerOfTwo(final int a)
  6. ceilInt(Double d, double intv)
  7. ceilInt(final double x)
  8. ceilLogBaseTwo(final int i)
  9. ceilMaskPOT(int n)