char只是一个基本类型,而String 是一个类,可以直接引用。
byte[]是字节数组类型//将指定byte数组以16进制的形式打印到控制台 public static void printHexString( byte[] b) { for (int i = 0; i < b.length; i++) { String hex = Integer.toHexString(b[i] & 0xFF); if (hex.length() == 1) { hex = '0' + hex; } System.out.print(hex.toUpperCase() ); } }/** *//**
*把字节数组转换成16进制字符串
*@param bArray
*@return
*/
public static final StringbytesToHexString(byte[] bArray) {
StringBuffer sb = new StringBuffer(bArray.length);
String sTemp;
for (int i = 0; i < bArray.length; i++) {
sTemp = Integer.toHexString(0xFF & bArray[i]);
if (sTemp.length() < 2)
sb.append(0);
sb.append(sTemp.toUpperCase());
}
return sb.toString();
}