public static byte[] toByteArray(String hex) {
    byte[] bytes = new byte[hex.length() / 2];
    for (int i = 0; i < bytes.length; i++) {
      int index = i * 2;
      int v = Integer.parseInt(hex.substring(index, index + 2), 16);
      bytes[i] = (byte) v;
    }
    return bytes;
  }
Converts a hex string to a byte array.

@param hex the hex string
@return the byte array
geode-core/src/main/java/org/apache/geode/internal/util/Hex.java