JAVA code:
private static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
-------------------------------------------
C code:
static void Bytes2HexStr(char *src,int srcLen,unsigned char *des)
{
unsigned char *res;
int i=0;
res = des;
while(srcLen>0)
{
sprintf((char*)(res+i*2),"%02x",*(src+i));
i++;
srcLen--;
}
}