Class BitUtil


  • public class BitUtil
    extends Object
    Based on code from: Derby - Class org.apache.derbyTesting.unitTests.util.BitUtil
    Author:
    paul
    • Constructor Detail

      • BitUtil

        public BitUtil()
    • 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 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