Java Number Round roundUpToPowerOf2(long val)

Here you can find the source of roundUpToPowerOf2(long val)

Description

round Up To Power Of

License

Apache License

Declaration

public static long roundUpToPowerOf2(long val) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

public class Main {
    public static long roundUpToPowerOf2(long val) {
        return 1L << log2Ceiling(val);
    }//from  ww  w .  j a  va  2  s  .c o  m

    public static int log2Ceiling(long val) {
        // Formula is based on the Long.numberOfLeadingZeros() javadoc comment.
        return 64 - Long.numberOfLeadingZeros(val - 1);
    }
}

Related

  1. roundUpToMultiple(long val, int factor)
  2. roundUpToNearest(double number, double nearest)
  3. roundUpToNearestEightBytes(long result)
  4. roundUpToNearestPowerOfTwoIfGreaterThanZero(final int value)
  5. roundUpToPowerOf2(int number)
  6. roundUpToPowerOf2Factor(long val, long factor)
  7. roundUpToPowerOfTwo(int i)
  8. roundUpToPowerOfTwo(int p_151236_0_)
  9. roundUpToPowerOfTwo(int v)