Java Power of 2 nextPowerOf2(int v)

Here you can find the source of nextPowerOf2(int v)

Description

next Power Of

License

Open Source License

Declaration

public static int nextPowerOf2(int v) 

Method Source Code

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

Related

  1. nextPowerOf2(final int n)
  2. nextPowerOf2(int n)
  3. nextPowerOf2(int n)
  4. nextPowerOf2(int n)
  5. nextPowerOf2(int n)
  6. nextPowerOf2(int x)
  7. nextPowerOf2(int x)
  8. nextPowerOfTwo(final int targetSize)
  9. nextPowerOfTwo(final long nValue)