Here you can find the source of nextPowerOfTwo(int i)
public static int nextPowerOfTwo(int i)
//package com.java2s; //License from project: Apache License public class Main { public static int nextPowerOfTwo(int i) { i -= 1;/*from ww w . ja v a 2s. c o m*/ i |= (i >> 1); i |= (i >> 2); i |= (i >> 4); i |= (i >> 8); i |= (i >> 16); return i + 1; } public static long nextPowerOfTwo(long i) { i -= 1; i |= (i >> 1); i |= (i >> 2); i |= (i >> 4); i |= (i >> 8); i |= (i >> 16); i |= (i >> 32); return i + 1; } }