* byte转bcd码
*
* @author wst 2023年9月13日 下午3:13:52
* @param bytes
* @return
*/
public static String ByteArrayToHexString(byte[] bytes) { StringBuilder sb = new StringBuilder();
for (byte aByte : bytes) { String hex = Integer.toHexString(0xFF & aByte);
if (hex.length() == 1) { sb.append('0'); }
sb.append(hex);
}
return sb.toString().toUpperCase();
}
* 十六进制BCD码转ASCII码
* @author wst 2023年10月11日 下午6:17:02
* @param hexStr
* @return
*/
public static String HexToString(String hexStr) { StringBuilder sb = new StringBuilder();
StringBuilder temp = new StringBuilder();
for (int i = 0; i < hexStr.length() - 1; i += 2) {
String output = hexStr.substring(i, (i + 2));
int decimal = Integer.parseInt(output, 16);
sb.append((char) decimal);
temp.append(decimal);
}
return sb.toString();
}