请求信息十六进制显示、请求信息ASCll码显示
请求信息十六进制显示
代码案例:
private static String byteArr2HexStr(byte[] buf,int len){ StringBuffer sbuffer = new StringBuffer(); int cnt = 0; for (int i=0;i<len;i++){ sbuffer.append(byte2Hex(buf[i])+" "); cnt++; if (cnt % 8 == 0) sbuffer.append(" "); if (cnt % 16 == 0) sbuffer.append("\r\n"); } return sbuffer.toString(); } private static String byte2Hex(byte bt){ int lo = bt & 0b00001111; int hi = (bt & 0b11110000) >> 4; char clo = arr[lo]; char chi = arr[hi]; return chi + "" +clo; }
运行结果:
请求信息ASCll码显示
private static String byteArr2HexStr(byte[] buf,int len){ StringBuffer sbuffer = new StringBuffer(); StringBuffer sb1 = new StringBuffer(); StringBuffer sb2 = new StringBuffer(); int cnt = 0; for (int i=0;i<len;i++){ sb1.append(byte2Hex(buf[i])+" "); if (buf[i] >= 0x20 && buf[i] <= 0x7e){ sb2.append((char) buf[i]); }else { sb2.append("."); } cnt++; if (cnt % 8 == 0) sb1.append(" "); if (cnt % 16 == 0) { sbuffer.append(sb1).append(sb2).append("\r\n"); sb1 = new StringBuffer(); sb2 = new StringBuffer(); cnt = 0; } } return sbuffer.toString(); }
运行结果