int strtohex(const char *ch)
{
int i=0, tmp, result=0;
for(i=0; i
if((ch[i]>='0')&&(ch[i]<='9'))
tmp = ch[i]-'0';
else if((ch[i]>='A')&&(ch[i]<='F'))
tmp = ch[i]-'A'+10;
else if((ch[i]>='a')&&(ch[i]<='f'))
tmp = ch[i]-'a'+10;
else
return -1; /* 出错了 */
result = result*16+tmp; /* 转成16进制数后加起来 */
}
return result;
}
字符串转换为hex,我用的这个。