Here you can find the source of roundUpToPowerOf2(int number)
public static int roundUpToPowerOf2(int number)
//package com.java2s; //License from project: Apache License public class Main { public static int roundUpToPowerOf2(int number) { // assert number >= 0 : "number must be non-negative"; int rounded = number >= Integer.MAX_VALUE ? Integer.MAX_VALUE : (rounded = Integer.highestOneBit(number)) != 0 ? (Integer.bitCount(number) > 1) ? rounded << 1 : rounded : 1;//from w w w .j a va2 s. c om return rounded; } }