jaulib v1.3.0
Jau Support Library (C++, Java, ..)
|
Static Public Member Functions | |
static int | getBitMask (final int n) |
Returns the 32 bit mask of n-bits, i.e. More... | |
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: More... | |
static final boolean | isPowerOf2 (final int n) |
Returns true if the given integer is a power of 2. More... | |
static final int | nextPowerOf2 (int n) |
Returns the next higher power of 2 of 32-bit of given n @endiliteral. More... | |
static final int | roundToPowerOf2 (final int n) |
If the given n is not isPowerOf2(int) return nextPowerOf2(int) , otherwise return n unchanged. More... | |
Static Public Attributes | |
static final int | UNSIGNED_INT_MAX_VALUE = 0xffffffff |
Maximum 32 bit Unsigned Integer Value: 0xffffffff == {@value}. More... | |
static final int | MAX_POWER_OF_2 = 1 << ( Integer.SIZE - 2 ) |
Maximum 32bit integer value being of isPowerOf2(int) . More... | |
Definition at line 26 of file BitMath.java.
|
static |
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/
<p<blockquote>
We rely on the JVM spec Integer#SIZE
== 32.
Definition at line 68 of file BitMath.java.
|
static |
Returns the 32 bit mask of n-bits, i.e.
n low order 1's.
Implementation handles n == 32.
IndexOutOfBoundsException | if b is out of bounds, i.e. > 32 |
Definition at line 45 of file BitMath.java.
|
static |
Returns true
if the given integer is a power of 2.
Source: bithacks: http://www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
Definition at line 94 of file BitMath.java.
|
static |
Returns the next higher power of 2 of 32-bit of given n @endiliteral.
Source: bithacks: http://www.graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
We rely on the JVM spec Integer#SIZE
== 32.
Definition at line 107 of file BitMath.java.
|
static |
If the given n
is not isPowerOf2(int)
return nextPowerOf2(int)
, otherwise return n
unchanged.
return isPowerOf2(n) ? n : nextPowerOf2(n);
<p<blockquote>
We rely on the JVM spec Integer#SIZE
== 32.
Definition at line 127 of file BitMath.java.
|
static |
Maximum 32bit integer value being of isPowerOf2(int)
.
We rely on the JVM spec Integer#SIZE
== 32.
Definition at line 36 of file BitMath.java.
|
static |
Maximum 32 bit Unsigned Integer Value: 0xffffffff
== {@value}.
Definition at line 28 of file BitMath.java.