jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Static Public Member Functions | Static Public Attributes | List of all members
org.jau.util.BitMath Class Reference
Collaboration diagram for org.jau.util.BitMath:

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...
 

Detailed Description

Definition at line 26 of file BitMath.java.

Member Function Documentation

◆ bitCount()

static final int org.jau.util.BitMath.bitCount ( int  n)
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.

Here is the caller graph for this function:

◆ getBitMask()

static int org.jau.util.BitMath.getBitMask ( final int  n)
static

Returns the 32 bit mask of n-bits, i.e.

n low order 1's.

Implementation handles n == 32.

Exceptions
IndexOutOfBoundsExceptionif b is out of bounds, i.e. > 32

Definition at line 45 of file BitMath.java.

Here is the caller graph for this function:

◆ isPowerOf2()

static final boolean org.jau.util.BitMath.isPowerOf2 ( final int  n)
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.

Here is the caller graph for this function:

◆ nextPowerOf2()

static final int org.jau.util.BitMath.nextPowerOf2 ( int  n)
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.

Here is the caller graph for this function:

◆ roundToPowerOf2()

static final int org.jau.util.BitMath.roundToPowerOf2 ( final int  n)
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.

Here is the call graph for this function:

Member Data Documentation

◆ MAX_POWER_OF_2

final int org.jau.util.BitMath.MAX_POWER_OF_2 = 1 << ( Integer.SIZE - 2 )
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.

◆ UNSIGNED_INT_MAX_VALUE

final int org.jau.util.BitMath.UNSIGNED_INT_MAX_VALUE = 0xffffffff
static

Maximum 32 bit Unsigned Integer Value: 0xffffffff == {@value}.

Definition at line 28 of file BitMath.java.


The documentation for this class was generated from the following file: