Here you can find the source of nextPowerOf2(int x)
Parameter | Description |
---|---|
x | the original value |
public static int nextPowerOf2(int x)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w .java2s .c o m * Get the value that is equal or higher than this value, and that is a * power of two. * * @param x the original value * @return the next power of two value */ public static int nextPowerOf2(int x) { long i = 1; while (i < x && i < (Integer.MAX_VALUE / 2)) { i += i; } return (int) i; } }