Class BitConverter


  • public class BitConverter
    extends java.lang.Object
    Converts from/to: byte arrays, integral values, and hex strings.
    • Constructor Summary

      Constructors 
      Constructor Description
      BitConverter()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] toBytes​(long value, int length)
      Converts a long value to byte array.
      static byte[] toBytes​(java.lang.String data)
      Convert a hex string to a byte array.
      static java.lang.String toHex​(byte[] data)
      Convert a byte array to a hex representation.
      static long toLong​(byte[] bytes, int index, int length)
      Converts a byte array to a long value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BitConverter

        public BitConverter()
    • Method Detail

      • toBytes

        public static byte[] toBytes​(long value,
                                     int length)
        Converts a long value to byte array.
        Parameters:
        value - The value to be converted.
        length - The length of the byte array to be returned.
        Returns:
        A byte array representation of the value.
      • toLong

        public static long toLong​(byte[] bytes,
                                  int index,
                                  int length)
        Converts a byte array to a long value. Little endian only.
        Parameters:
        bytes - The byte array to be converted.
        index - The starting index of the data in the array that will be converted.
        length - The length of the data that will be converted.
        Returns:
        The long value representation of the byte array.
      • toHex

        public static java.lang.String toHex​(byte[] data)
        Convert a byte array to a hex representation.
        Parameters:
        data - The byte array to be converted.
        Returns:
        The hex string representation.
      • toBytes

        public static byte[] toBytes​(java.lang.String data)
        Convert a hex string to a byte array.
        Parameters:
        data - The hex string to be converted.
        Returns:
        The byte array converted from the string.