if(a.length()==1){ a="0"+a;},为什么要给a特地加个0?倒数第九行

private void readComm() {
byte[] readBuffer = new byte[15];
try {
int len = 0;
while ((len = inputStream.read(readBuffer)) != -1) {
test += new String(readBuffer,0, len).trim();
break;
}
StringBuilder sb=new StringBuilder();
for (byte b : readBuffer) {
String a="";
if (b < 0) {
//byte的范围是-128到+127
int i = 128 + (int) b + 127 + 1;
//转换成16进制
a=Integer.toHexString(i);

            }else {
                a=Integer.toHexString(b);
            }
           if(a.length()==1){
                a="0"+a;
           }
            sb.append(a);
        }
        System.out.println("接收的数据:"+sb);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

16进制中,两个字符为一字节
加0的目的是凑齐两个字符,标准化输出

因为你算出的结果是数字,要转换成对应的ascii输出,所以要加上'0'