Java Utililty Methods XML Hex

List of utility methods to do XML Hex

Description

The list of methods to do XML Hex are organized into topic(s).

Method

StringbyteArrayToHex(final byte[] arr)
Converts a byte array into a hex representation with a space between each byte e.g 00 00 01 00 05 59 B3
final StringBuilder sb = new StringBuilder();
if (arr != null) {
    for (final byte b : arr) {
        final byte[] oneByteArr = new byte[1];
        oneByteArr[0] = b;
        sb.append(DatatypeConverter.printHexBinary(oneByteArr));
        sb.append(" ");
return sb.toString().replaceAll(" $", "");
StringbyteArrayToHexString(byte[] bytes)
Convert a byte array into a hex string.
return DatatypeConverter.printHexBinary(bytes);
StringbytesToHex(byte[] b)
bytes To Hex
return javax.xml.bind.DatatypeConverter.printHexBinary(b);
StringbytesToHex(byte[] bytes)

Convert an array of bytes to it's Hex-String representation

return javax.xml.bind.DatatypeConverter.printHexBinary(bytes);
StringbytesToHex(final byte[] bytes)
Converts the passed bytes to a hex string
return bytes == null ? "" : DatatypeConverter.printHexBinary(bytes);
StringbytesToHexStr(byte[] array)
bytes To Hex Str
if (array == null)
    return null;
else
    return DatatypeConverter.printHexBinary(array);
StringconvertByteArrayToHexString(byte[] byteArray)
Converts a Byte Array to Hex String.
return DatatypeConverter.printHexBinary(byteArray);
StringconvertStringToHex(String str)
convert String To Hex
char[] chars = str.toCharArray();
StringBuffer hex = new StringBuffer();
for (int i = 0; i < chars.length; i++) {
    hex.append(Integer.toHexString((int) chars[i])).append(" ");
return hex.toString();
StringencodeHex(byte[] bytes)
Turns an array of bytes into a String representing each byte as an unsigned hex number.
return DatatypeConverter.printHexBinary(bytes).toLowerCase();
byte[]fromHex(String hex)
Convert provided hex string representation in format AA:FF:47:11 byte array.
if (hex != null) {
    return DatatypeConverter.parseHexBinary(hex.replaceAll("[^0-9a-fA-F]+", ""));
return new byte[0];