Java Power of 2 nextPowerOfTwo(int value)

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

Description

Returns the smallest power-of-two that is greater than or equal to the supplied (positive) value.

License

Open Source License

Declaration

public static int nextPowerOfTwo(int value) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  ww .  jav  a  2  s  . c  o  m
     * Returns the smallest power-of-two that is greater than or equal to the supplied (positive)
     * value.
     */
    public static int nextPowerOfTwo(int value) {
        return (Integer.bitCount(value) > 1) ? (Integer.highestOneBit(value) << 1) : value;
    }
}

Related

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