Java Power of 2 nextPowerOfTwo(int value)

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

Description

next Power Of Two

License

Open Source License

Declaration

public static int nextPowerOfTwo(int value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static int nextPowerOfTwo(int value) {
        if (value == 0)
            return 1;
        if ((value & value - 1) == 0)
            return value;
        value |= value >> 1;/* w  ww  .j  av a2  s  . com*/
        value |= value >> 2;
        value |= value >> 4;
        value |= value >> 8;
        value |= value >> 16;
        return value + 1;
    }
}

Related

  1. nextPowerOfTwo(int i)
  2. nextPowerOfTwo(int i)
  3. nextPowerOfTwo(int n)
  4. nextPowerOfTwo(int num)
  5. nextPowerOfTwo(int value)
  6. nextPowerOfTwo(int value)
  7. nextPowerOfTwo(int value)
  8. nextPowerOfTwo(int x)
  9. nextPowerOfTwo(int x)