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