ByteBuf data=Unpooled.buffer();
byte tempByte[]=new byte[10];
int [] tempInt=new int[10];
- ByteBuf转为byte[]
System.arraycopy(data.array(),0,tempByte,0,10);
- byte[] 转为无符号int (char)
for(int i=0;i<tempLen;i++){
tempInt [i]=(tempbyte [i]&0xff);
}
- int转为byte[]
for(int i=0;i<64;i++){
tempByte[i]=(byte)(tempInt[i]&0xff);
}
- byte[]转String
public String bytesToHexString(byte[] bArr) {
StringBuffer sb = new StringBuffer(bArr.length);
String sTmp;
for (int i = 0; i < bArr.length; i++) {
sb.append("0x");
sTmp = Integer.toHexString(0xFF & bArr[i]);
if (sTmp.length() < 2)
sb.append(0);
sb.append(sTmp.toUpperCase());
sb.append(",");
if(i== (bArr.length-1)){
sb.append("end");
}
}
return sb.toString();
}