日期:2014-05-20 浏览次数:20896 次
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());
------解决方案--------------------
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(); }