/* Byte值转换为bytes字符串
* @param src:Byte指针 srcLen:src长度 des:转换得到的bytes字符串
**/
static void Bytes2HexStr(BYTE *src,int srcLen,BYTE *des)
{
BYTE *res;
int i=0;
res = des;
while(srcLen>0)
{
sprintf((char*)(res+i*2),"%02x",*(src+i));
i++;
srcLen--;
}
}
/**
* bytes字符串转换为Byte值
* @param String src Byte字符串,每个Byte之间没有分隔符
* @return byte[]
*/
static BYTE* hexStr2Bytes(string src)
{
char *strEnd;
int m=0;
int len = src.length()/2;
BYTE* ret = new BYTE[len];
for(int i =0;i<len;i++)
{
m = i*2;
string subs = src.substr(m,2);
ret[i] = strtol(subs.c_str(),&strEnd,16);
}
return ret;
}
Bytes2HexStr与hexStr2Bytes
最新推荐文章于 2021-05-22 18:20:38 发布