Here you can find the source of nextPowerOf2(int v)
public static int nextPowerOf2(int v)
//package com.java2s; //License from project: Open Source License public class Main { public static int nextPowerOf2(int v) { v--;/*from w w w . j a va 2 s . c o m*/ v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } }