public static byte[] stringTobytes(String hexString) { String stringProcessed = hexString.trim().replaceAll("0x", ""); stringProcessed = stringProcessed.replaceAll("\\s+", ""); byte[] data = new byte[stringProcessed.length() / 2]; int i = 0; for(int j = 0; i <= stringProcessed.length() - 1; i += 2) { byte character = (byte)Integer.parseInt(stringProcessed.substring(i, i + 2), 16); data[j] = character; ++j; } return data;}
//byte转换16进制字符串
public static final String bytesToHexString(byte[] bArray) { StringBuffer sb = new StringBuffer(bArray.length); String sTemp; for (int i = 0; i < bArray.length; i++) { sTemp = Integer.toHexString(0xFF & bArray[i]); if (sTemp.length() < 2) sb.append(0); sb.append(sTemp.toUpperCase()); } return sb.toString();}