HEX格式数据转换成十六进制字符串

时间:2022-09-16 10:17:29
技术交流群:233513714

 1 /**

  * Hex格式数据转换成十六进制字符串

  * @param src

  */

 public void bytesToHexString(byte[] by){
StringBuilder stringBuilder = new StringBuilder("");
for (int i = 0; i < by.length; i++) {
int in = by[i] & 0xFF;
String str= Integer.toHexString(in);
if (str.length() < 2) {
stringBuilder.append(0);
}
stringBuilder.append(str);
}
System.out.println(stringBuilder.toString());
}