Java Ceil ceilPowerOf2(final long x)

Here you can find the source of ceilPowerOf2(final long x)

Description

Get the smallest long which is a power of 2 and > x.

License

Open Source License

Parameter

Parameter Description
x number being checked.

Return

integer which is a power of 2 > x.

Declaration

public static long ceilPowerOf2(final long x) 

Method Source Code

//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;
    }
}

Related

  1. ceilMaskPOT(int n)
  2. ceilMultiple(float source, float multiple)
  3. ceilPositive(float x)
  4. ceilPoT(int arg)
  5. ceilPow2(int v)
  6. ceilPowerOf2(int x)
  7. ceilPowerOf2Bits(final long x)
  8. ceilPrime(long p)
  9. ceilSec(long milli)