Here you can find the source of roundUpPower2(int v)
Parameter | Description |
---|---|
v | the value to be rounded |
public static final int roundUpPower2(int v)
//package com.java2s; public class Main { /**//from w w w . java2 s . c om * @param v the value to be rounded * @return the next power of two greater or equal to <i>v</i> */ public static final int roundUpPower2(int v) { switch (Integer.bitCount(v)) { case 0: return (1); case 1: return (v); default: return (Integer.highestOneBit(v) << 1); } } }