Package org.openhab.core.util
Class HexUtils
java.lang.Object
org.openhab.core.util.HexUtils
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 Summary
Modifier and TypeMethodDescriptionstatic StringbytesToHex(byte[] bytes) Converts a byte array into a hex string (in format "0123456789ABCDEF").static StringbytesToHex(byte[] bytes, @Nullable CharSequence delimiter) Converts a byte array into a hex string with a given delimiter.static byte[]byteToHex(byte value) static BigIntegerhexBlockToBigInteger(String hexBlock) Convert a white space delimited hex block to aBigInteger.static byte[]hexBlockToBytes(String hexBlock) Convert a white space delimited hex block to a byte array.static bytehexToByte(byte high, byte low) static byte[]hexToBytes(String hexString) Converts an hex string (in format "0123456789ABCDEF") into a byte arraystatic byte[]hexToBytes(String hexString, String delimiter) Converts an hex string (eg. format "01-23-45") into a byte array
-
Method Details
-
bytesToHex
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 arraydelimiter- a delimiter that is placed between every two bytes- Returns:
- the corresponding hex string
-
bytesToHex
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
Converts an hex string (eg. format "01-23-45") into a byte array- Parameters:
hexString- the hex stringdelimiter- a delimiter that was placed between every two bytes- Returns:
- the corresponding byte array
-
hexToBytes
Converts an hex string (in format "0123456789ABCDEF") into a byte array- Parameters:
hexString- the hex string- Returns:
- the corresponding byte array
-
hexBlockToBytes
Convert a white space delimited hex block to a byte array.- Parameters:
hexBlock- the hex block- Returns:
- the byte array
- Throws:
IllegalArgumentException- if a value is invalid
-
hexBlockToBigInteger
Convert a white space delimited hex block to aBigInteger.- Parameters:
hexBlock- the hex block- Returns:
- the BigInteger value
- Throws:
IllegalArgumentException- if a value is invalid
-
hexToByte
public static byte hexToByte(byte high, byte low)
-