Package com.jogamp.common.util
Class Bitfield.Util
- java.lang.Object
-
- com.jogamp.common.util.Bitfield.Util
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_POWER_OF_2
Maximum 32bit integer value being ofisPowerOf2(int)
.
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
bitCount(int n)
Returns the number of set bits within given 32bit integer in O(1) using a HAKEM 169 Bit Count inspired implementation:static int
getBitMask(int n)
Returns the 32 bit mask of n-bits, i.e.static boolean
isPowerOf2(int n)
Returnstrue
if the given integer is a power of 2static int
nextPowerOf2(int n)
Returns the next higher power of 2 of 32-bit of givenn
static int
roundToPowerOf2(int n)
-
-
-
Field Detail
-
MAX_POWER_OF_2
public static final int MAX_POWER_OF_2
Maximum 32bit integer value being ofisPowerOf2(int)
.We rely on the JVM spec
Integer.SIZE
== 32.- See Also:
- Constant Field Values
-
-
Method Detail
-
getBitMask
public static int getBitMask(int n)
Returns the 32 bit mask of n-bits, i.e. n low order 1’s.Implementation handles n == 32.
- Throws:
IndexOutOfBoundsException
- ifb
is out of bounds, i.e. > 32
-
bitCount
public static final int bitCount(int n)
Returns the number of set bits within given 32bit integer in O(1) using a HAKEM 169 Bit Count inspired implementation:http://www.inwap.com/pdp10/hbaker/hakmem/hakmem.html http://home.pipeline.com/~hbaker1/hakmem/hacks.html#item169 http://tekpool.wordpress.com/category/bit-count/ http://www.hackersdelight.org/
We rely on the JVM spec
Integer.SIZE
== 32.
-
isPowerOf2
public static final boolean isPowerOf2(int n)
Returnstrue
if the given integer is a power of 2Source: bithacks: http://www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
-
nextPowerOf2
public static final int nextPowerOf2(int n)
Returns the next higher power of 2 of 32-bit of givenn
Source: bithacks: http://www.graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
We rely on the JVM spec
Integer.SIZE
== 32.
-
roundToPowerOf2
public static final int roundToPowerOf2(int n)
If the givenn
is notisPowerOf2(int)
returnnextPowerOf2(int)
, otherwise returnn
unchanged.return isPowerOf2(n) ? n : nextPowerOf2(n);
We rely on the JVM spec
Integer.SIZE
== 32.
-
-