Here you can find the source of nextPowerOfTwo(int n)
public static int nextPowerOfTwo(int n)
//package com.java2s; /**//from w w w. j a v a 2s . co m * This class is part of JCodec ( www.jcodec.org ) This software is distributed * under FreeBSD License * * @author The JCodec project * */ public class Main { public static int nextPowerOfTwo(int n) { n = n - 1; n = n | (n >> 1); n = n | (n >> 2); n = n | (n >> 4); n = n | (n >> 8); n = n | (n >> 16); n = n + 1; return n; } }