CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.util
Class BitHelper

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.BitHelper
Direct Known Subclasses:
ExternalizableHelper, PartitionSet

public class BitHelper
extends Base

A collection of methods for bit-based operations.

Author:
cp 2006.01.10 starting from the MemberSet implementation

Constructor Summary
BitHelper()
           
 
Method Summary
static int countBits(byte b)
          Count the number of bits set in the passed integral value.
static int countBits(int n)
          Count the number of bits set in the passed integral value.
static int countBits(long l)
          Count the number of bits set in the passed integral value.
static int indexOfLSB(byte b)
          Determine the least significant bit of the passed integral value.
static int indexOfLSB(int n)
          Determine the least significant bit of the passed integral value.
static int indexOfLSB(long l)
          Determine the least significant bit of the passed integral value.
static int indexOfMSB(byte b)
          Determine the most significant bit of the passed integral value.
static int indexOfMSB(int n)
          Determine the most significant bit of the passed integral value.
static int indexOfMSB(long l)
          Determine the most significant bit of the passed integral value.
static String toBitString(byte b)
          Convert a byte to a String of ones and zeros.
static String toBitString(int n)
          Convert an int to a String of ones and zeros.
static String toBitString(long l)
          Convert a long to a String of ones and zeros.
 

Constructor Detail

BitHelper

public BitHelper()
Method Detail

countBits

public static int countBits(byte b)
Count the number of bits set in the passed integral value.

Parameters:
b - a byte
Returns:
the number of bits set in the byte [0..8]

countBits

public static int countBits(int n)
Count the number of bits set in the passed integral value.

Parameters:
n - an int
Returns:
the number of bits set in the int [0..32]

countBits

public static int countBits(long l)
Count the number of bits set in the passed integral value.

Parameters:
l - a long
Returns:
the number of bits set in the long [0..64]

indexOfMSB

public static int indexOfMSB(byte b)
Determine the most significant bit of the passed integral value.

Parameters:
b - a byte
Returns:
-1 if no bits are set; otherwise, the bit position p of the most significant bit such that 1 << p is the most significant bit of b

indexOfMSB

public static int indexOfMSB(int n)
Determine the most significant bit of the passed integral value.

Parameters:
n - an int
Returns:
-1 if no bits are set; otherwise, the bit position p of the most significant bit such that 1 << p is the most significant bit of n

indexOfMSB

public static int indexOfMSB(long l)
Determine the most significant bit of the passed integral value.

Parameters:
l - a long
Returns:
-1 if no bits are set; otherwise, the bit position p of the most significant bit such that 1 << p is the most significant bit of l

indexOfLSB

public static int indexOfLSB(byte b)
Determine the least significant bit of the passed integral value.

Parameters:
b - a byte
Returns:
-1 if no bits are set; otherwise, the bit position p of the least significant bit such that 1 << p is the least significant bit of b

indexOfLSB

public static int indexOfLSB(int n)
Determine the least significant bit of the passed integral value.

Parameters:
n - an int
Returns:
-1 if no bits are set; otherwise, the bit position p of the least significant bit such that 1 << p is the least significant bit of n

indexOfLSB

public static int indexOfLSB(long l)
Determine the least significant bit of the passed integral value.

Parameters:
l - a long
Returns:
-1 if no bits are set; otherwise, the bit position p of the least significant bit such that 1 << p is the least significant bit of l

toBitString

public static String toBitString(byte b)
Convert a byte to a String of ones and zeros.

Parameters:
b - a byte
Returns:
a String of ones and zeros representing the byte value

toBitString

public static String toBitString(int n)
Convert an int to a String of ones and zeros.

Parameters:
n - an int
Returns:
a String of ones and zeros representing the int value

toBitString

public static String toBitString(long l)
Convert a long to a String of ones and zeros.

Parameters:
l - a long
Returns:
a String of ones and zeros representing the long value

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation