Here you can find the source of ceilPowerOf2(final long x)
Parameter | Description |
---|---|
x | number being checked. |
public static long ceilPowerOf2(final long x)
//package com.java2s; public class Main { /**// w w w. j a va 2 s .co m * Get the smallest long which is a power of 2 and > x. Undefined for negative * numbers or numbers so large that there is no positive power of 2 available. * * @param x number being checked. * @return integer which is a power of 2 > x. */ public static long ceilPowerOf2(final long x) { if (x >= (1L << 62) || x < 0) { throw new IllegalArgumentException("Number out of range:" + x); } long i = 1L; while (i <= x) { i = i << 1; } return i; } }