Java Power of 2 nextPowerOfTwo(int n)

Here you can find the source of nextPowerOfTwo(int n)

Description

next Power Of Two

License

BSD License

Declaration

public static int nextPowerOfTwo(int n) 

Method Source Code

//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;
    }
}

Related

  1. nextPowerOfTwo(final int targetSize)
  2. nextPowerOfTwo(final long nValue)
  3. nextPowerOfTwo(int i)
  4. nextPowerOfTwo(int i)
  5. nextPowerOfTwo(int i)
  6. nextPowerOfTwo(int num)
  7. nextPowerOfTwo(int value)
  8. nextPowerOfTwo(int value)
  9. nextPowerOfTwo(int value)