Package ubic.basecode.dataStructure
Class BitUtil
java.lang.Object
ubic.basecode.dataStructure.BitUtil
Based on code from: Derby - Class org.apache.derbyTesting.unitTests.util.BitUtil
- Author:
- paul
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean[]
asBools
(byte[] bytes) static byte[]
clear
(byte[] bytes, int position) Clear the bit at the specified positionstatic int
count
(byte[] bytes) static boolean
get
(byte[] bytes, int position) Check to see if the specified bit is setstatic String
prettyPrint
(byte[] bytes) static byte[]
set
(byte[] bytes, int position) Set the bit at the specified position
-
Constructor Details
-
BitUtil
public BitUtil()
-
-
Method Details
-
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
- 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
-