求助:java的将byte[](byte数组)转换成十六进制字符串方法,谢谢。
------解决方案--------------------------------------------------------
- Java code
byte[] input=.....StringBuffer buff = new StringBuffer(input.length*4);for(int i=0;i<input.length;i++){ buff.append(String.format("0x%02X",input[i]));}system.out.println(buff.toString());
------解决方案--------------------------------------------------------
- Java code
public static String byteArrToHexStr(byte[] arr){ StringBuilder sb = new StringBuilder("0x "); for(int i=0;i<arr.length;i++){ int b = arr[i]; int high = (arr[i]>>4 & 0x0f); int low = arr[i] & 0x0f; System.out.println(high+","+low); if(high >= 10)sb.append((char)(high-10+'A')); else sb.append(high); if(low >= 10)sb.append((char)(low-10+'A')); else sb.append(low); sb.append(" "); } return sb.toString(); }