code: public static byte[] asByteArray(String hex) {
          byte[] bts = new byte[hex.length() / 2];
          for (int i = 0; i < bts.length; i++) {
              bts[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2),
                      16);
          }
  
          return bts;
      }
docs: Converts a hex string representation to a byte array.
  
  @param hex the string holding the hex values
  @return the resulting byte array