Here you can find the source of nextPowerOf2(int n)
Parameter | Description |
---|---|
n | The value |
public static int nextPowerOf2(int n)
//package com.java2s; //License from project: Open Source License public class Main { /**/* ww w. j a va 2 s. c om*/ * Returns the next power of 2 that is greater or equal to the specified value. * * @param n The value * @return The next power of power of 2 */ public static int nextPowerOf2(int n) { assert n > 0; n--; n |= n >>> 1; n |= n >>> 2; n |= n >>> 4; n |= n >>> 8; n |= n >>> 16; return n + 1; } }