Class BitTools


  • public class BitTools
    extends Object
    Author:
    Tilmann Zaeschke
    • Constructor Summary

      Constructors 
      Constructor Description
      BitTools()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean getAndCopyBit​(long[] src, int posBit, long[] dst)  
      static boolean getBit​(long[] ba, int posBit)  
      static boolean getBit​(long l, int posBit)  
      static long merge​(long[] srcV, int src1, int src2, int nBits)
      Merges two long values into a single value by interleaving there respective bits.
      static long[] mergeLong​(int nBitsPerValue, long[] src)
      Merges long values into a single value by interleaving there respective bits.
      static long reverse​(long l, int usedBits)
      Reverses the value, considering that not all 64bits of the long value are used.
      static long set0​(long ba, int posBit)  
      static long set1​(long ba, int posBit)  
      static void setBit​(long[] ba, int posBit, boolean b)  
      static long setBit​(long ba, int posBit, boolean b)  
      static void split​(long toSplit, long[] trgV, int trg1, int trg2, int nBits)
      Splits a value and write it to trgV at position trg1 and trg2.
      static long[] splitLong​(int dims, int nBitsPerValue, long[] toSplit)
      Splits a value and write it to trgV at position trg1 and trg2.
      static String toBinary​(long[] la, int DEPTH)  
      static String toBinary​(long l, int DEPTH)  
      static double toDouble​(long value)  
      static double[] toDouble​(long[] value, double[] ret)  
      static float toFloat​(long value)  
      static float[] toFloat​(long[] value, float[] ret)  
      static long toSortableLong​(double value)  
      static long[] toSortableLong​(double[] value, long[] ret)  
      static long toSortableLong​(float value)  
      static long[] toSortableLong​(float[] value, long[] ret)  
      static long toSortableLong​(String s)  
    • Constructor Detail

      • BitTools

        public BitTools()
    • Method Detail

      • toSortableLong

        public static long toSortableLong​(double value)
        Parameters:
        value - value to convert
        Returns:
        long representation.
      • toSortableLong

        public static long toSortableLong​(float value)
      • toDouble

        public static double toDouble​(long value)
      • toFloat

        public static float toFloat​(long value)
      • toSortableLong

        public static long[] toSortableLong​(double[] value,
                                            long[] ret)
        Parameters:
        value - Value to be transformed
        ret - The array used to store the return value
        Returns:
        long representation.
      • toSortableLong

        public static long[] toSortableLong​(float[] value,
                                            long[] ret)
      • toDouble

        public static double[] toDouble​(long[] value,
                                        double[] ret)
      • toFloat

        public static float[] toFloat​(long[] value,
                                      float[] ret)
      • toSortableLong

        public static long toSortableLong​(String s)
      • reverse

        public static long reverse​(long l,
                                   int usedBits)
        Reverses the value, considering that not all 64bits of the long value are used.
        Parameters:
        l - value to be reversed
        usedBits - Number of bits to be considered
        Returns:
        Reversed value
      • split

        public static void split​(long toSplit,
                                 long[] trgV,
                                 int trg1,
                                 int trg2,
                                 int nBits)
        Splits a value and write it to trgV at position trg1 and trg2. This is the inverse operation to merge(...).
        Parameters:
        toSplit - value to split
        trgV - return value
        trg1 - return position part 1
        trg2 - return position part 2
        nBits - Number of bits of source value
      • merge

        public static long merge​(long[] srcV,
                                 int src1,
                                 int src2,
                                 int nBits)
        Merges two long values into a single value by interleaving there respective bits. This is the inverse operation to split(...).
        Parameters:
        srcV - Source array
        src1 - Position of 1st source value
        src2 - Position of 2nd source value
        nBits - Number of bits of RESULT
        Returns:
        Merged result
      • mergeLong

        public static long[] mergeLong​(int nBitsPerValue,
                                       long[] src)
        Merges long values into a single value by interleaving there respective bits. This is the inverse operation to split(...).
        Parameters:
        src - Source array
        nBitsPerValue - Number of bits of each source value
        Returns:
        Merged result
      • splitLong

        public static long[] splitLong​(int dims,
                                       int nBitsPerValue,
                                       long[] toSplit)
        Splits a value and write it to trgV at position trg1 and trg2. This is the inverse operation to merge(...).
        Parameters:
        dims - number of splinters to split into
        toSplit - value to split
        nBitsPerValue - Number of bits of source value
        Returns:
        long[] with 'dims' entries
      • getBit

        public static boolean getBit​(long[] ba,
                                     int posBit)
        Parameters:
        ba - byte array
        posBit - Counts from left to right!!!
        Returns:
        current bit
      • getBit

        public static boolean getBit​(long l,
                                     int posBit)
        Parameters:
        l - bit set
        posBit - Counts from left to right!!!
        Returns:
        current bit
      • getAndCopyBit

        public static boolean getAndCopyBit​(long[] src,
                                            int posBit,
                                            long[] dst)
        Parameters:
        src - source array Reads a bit from src, writes it to dst and returns it.
        posBit - Counts from left to right
        dst - target array
        Returns:
        current bit
      • setBit

        public static void setBit​(long[] ba,
                                  int posBit,
                                  boolean b)
        Parameters:
        ba - byte array
        posBit - Counts from left to right (highest to lowest)!!!
        b - bit to set
      • setBit

        public static long setBit​(long ba,
                                  int posBit,
                                  boolean b)
      • set1

        public static long set1​(long ba,
                                int posBit)
      • set0

        public static long set0​(long ba,
                                int posBit)
      • toBinary

        public static String toBinary​(long[] la,
                                      int DEPTH)
      • toBinary

        public static String toBinary​(long l,
                                      int DEPTH)