/**
* 2011-04-26
* @author chase
* 字节数组转换为16进制字符串
*/
public class BytetoHex {
public static final String encodeHex(byte[] bytes) {
StringBuffer buf = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
if (((int)bytes[i] & 0xff) < 0x10) {
buf.append("0");
}
buf.append(Long.toString((int)bytes[i] & 0xff, 16));
}
return buf.toString();
}
public static void main(String[] args) {
byte By[]={34,12,4,-6,-8,55,127,88};
System.out.println(encodeHex(By));
}
}