Here you can find the source of roundUpToPowerOf2(long val)
public static long roundUpToPowerOf2(long val)
//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); } }