123456

 

16进制转换成字符串

inline int hex_to_str(const unsigned char *hex, int hexlen, char *str, int &strlen)
{
	int outhexlen = hexlen * 2 + 1;

	if (strlen < outhexlen)
	{
		return -1;
	}

	strlen = outhexlen;

	for (int i = 0; i < hexlen; ++i)
	{
		_snprintf(str + 2*i, 3, "%02X", (unsigned char)hex[i]);
	}

	return strlen;
}


int _tmain(int argc, _TCHAR* argv[])
{
	UCHAR SigBytes[24] = {0,1,2,3,4,5,6};
	char szByte[50] = {0};
	int nLen = 50;
	hex_to_str(SigBytes, 24, szByte, nLen);
	
	return 0;
}

posted on 2014-02-20 16:56  hgy413  阅读(447)  评论(0编辑  收藏  举报

导航