Here you can find the source of nextPowerOf2(final int n)
Parameter | Description |
---|---|
n | The value to find the next power of 2 above |
public static int nextPowerOf2(final int n)
//package com.java2s; public class Main { /**/*from w ww. j a va 2 s.c om*/ * Returns the next power of 2 superior to n. * * @param n * The value to find the next power of 2 above * @return The next power of 2 */ public static int nextPowerOf2(final int n) { return (int) Math.pow(2, 32 - Integer.numberOfLeadingZeros(n - 1)); } }