Package ubic.basecode.dataStructure
Class BitUtil
- java.lang.Object
-
- ubic.basecode.dataStructure.BitUtil
-
public class BitUtil extends Object
Based on code from: Derby - Class org.apache.derbyTesting.unitTests.util.BitUtil- Author:
- paul
-
-
Constructor Summary
Constructors Constructor Description BitUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean[]asBools(byte[] bytes)static byte[]clear(byte[] bytes, int position)Clear the bit at the specified positionstatic intcount(byte[] bytes)static booleanget(byte[] bytes, int position)Check to see if the specified bit is setstatic StringprettyPrint(byte[] bytes)static byte[]set(byte[] bytes, int position)Set the bit at the specified position
-
-
-
Method Detail
-
asBools
public static boolean[] asBools(byte[] bytes)
-
clear
public static byte[] clear(byte[] bytes, int position)Clear the bit at the specified position- Parameters:
bytes- the byte arrayposition- the bit to clear, starting from zero- Returns:
- the byte array with the cleared bit
- Throws:
IndexOutOfBoundsException- on bad position
-
count
public static int count(byte[] bytes)
- Parameters:
bytes-- Returns:
- The number of '1' bits.
-
get
public static boolean get(byte[] bytes, int position)Check to see if the specified bit is set- Parameters:
bytes- the byte arrayposition- the bit to check, starting from zero- Returns:
- true/false
- Throws:
IndexOutOfBoundsException- on bad position
-
prettyPrint
public static String prettyPrint(byte[] bytes)
- Parameters:
bytes-- Returns:
-
set
public static byte[] set(byte[] bytes, int position)Set the bit at the specified position- Parameters:
bytes- the byte arrayposition- the bit to set, starting from zero- Returns:
- the byte array with the set bit
- Throws:
IndexOutOfBoundsException- on bad position
-
-