parseByte2HexStr for c

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--;
        }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章