HexToBin

View Code
//************************************
// 函数: HexToBin
// 参数: const char * src
// 参数: unsigned char * bin
// 参数: int & len
// 返回: void
// 作用: 16进制 to 2进制
//************************************
void HexToBin(const char* src, unsigned char* bin, int &len)
{
//printf("key = %s\n",src);
char *temp = (char*)src;
char buf[100] = {0};
char *pBuf = buf;
int index = 0;
do
{
pBuf = buf ;
while(*temp!=',' && *temp != 0 && *temp != ' ')
*pBuf++ = *temp++;
*pBuf = 0;
// = atoi(buf);
sscanf(buf,"%x",&bin[index++]);
}
while(*temp++);
len = index;
}
原文地址:https://www.cnblogs.com/guyan/p/2277785.html