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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean[]
    asBools(byte[] bytes)
     
    static byte[]
    clear(byte[] bytes, int position)
    Clear the bit at the specified position
    static int
    count(byte[] bytes)
     
    static boolean
    get(byte[] bytes, int position)
    Check to see if the specified bit is set
    static String
    prettyPrint(byte[] bytes)
     
    static byte[]
    set(byte[] bytes, int position)
    Set the bit at the specified position

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 array
      position - 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 array
      position - 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 array
      position - the bit to set, starting from zero
      Returns:
      the byte array with the set bit
      Throws:
      IndexOutOfBoundsException - on bad position