1 十六进制的字符串->byte[] :
int len = (hex.length() / 2);
byte[] result = new byte[len];
char[] achar = hex.toCharArray();
for (int i = 0; i
intpos=i*2;
result[i] =(byte)((byte) "0123456789ABCDEF".indexOf(achar[pos]) <<4|(byte) "0123456789ABCDEF".indexOf(achar[pos+1]));
}
2 byte [] 转换成16 进制的字符串:
byte[] bArray;
StringBuffersb=newStringBuffer(bArray.length);
StringsTemp;
for(inti=0;i
sTemp=Integer.toHexString(0xFF&bArray[i]);
if(sTemp.length() <2)
sb.append(0);
sb.append(sTemp.toUpperCase());
}