Class HexUtils

java.lang.Object
org.openhab.core.util.HexUtils

@NonNullByDefault public class HexUtils extends Object
Static utility methods that are helpful when dealing with hex data and byte arrays.
Author:
Kai Kreuzer - Initial contribution, Martin van Wingerden - Implemented the reverse operation
  • Method Details

    • bytesToHex

      public static String bytesToHex(byte[] bytes, @Nullable CharSequence delimiter)
      Converts a byte array into a hex string with a given delimiter. Example: Delimiter "-" results in Strings like "01-23-45".
      Parameters:
      bytes - the byte array
      delimiter - a delimiter that is placed between every two bytes
      Returns:
      the corresponding hex string
    • bytesToHex

      public static String bytesToHex(byte[] bytes)
      Converts a byte array into a hex string (in format "0123456789ABCDEF").
      Parameters:
      bytes - the byte array
      Returns:
      the corresponding hex string
    • byteToHex

      public static byte[] byteToHex(byte value)
    • hexToBytes

      public static byte[] hexToBytes(String hexString, String delimiter)
      Converts an hex string (eg. format "01-23-45") into a byte array
      Parameters:
      hexString - the hex string
      delimiter - a delimiter that was placed between every two bytes
      Returns:
      the corresponding byte array
    • hexToBytes

      public static byte[] hexToBytes(String hexString)
      Converts an hex string (in format "0123456789ABCDEF") into a byte array
      Parameters:
      hexString - the hex string
      Returns:
      the corresponding byte array
    • hexToByte

      public static byte hexToByte(byte high, byte low)