Here you can find the source of nextPowerOf2(int n)
public static int nextPowerOf2(int n)
//package com.java2s; public class Main { /**// w w w . j a v a 2s .com * Returns the nearest power of 2, which is either n if n is already * a power of 2, or the next higher number than n which is a power of 2. */ public static int nextPowerOf2(int n) { int x = 1; while (x < n) { x <<= 1; } return x; } }