short nMAsciiHexToBinary(
unsigned char* vspSourceStr,
short vnSourceStrL,
unsigned char* vspDestStr) {
if(vnSourceStrL % 2)
return -1;
for(; vnSourceStrL > 0; vnSourceStrL -= 2) {
if(*vspSourceStr >= '0' &&
*vspSourceStr <= '9')
*vspDestStr = ((*vspSourceStr++) - '0') * 16;
else if(*vspSourceStr >= 'a' &&
*vspSourceStr <= 'f')
*vspDestStr = ((*vspSourceStr++) - 'a' + 10) * 16;
else if(*vspSourceStr >= 'A' &&
*vspSourceStr <= 'F')
*vspDestStr = ((*vspSourceStr++) - 'A' + 10) * 16;
else
return -1;
if(*vspSourceStr >= '0' &&
*vspSourceStr <= '9')
(*vspDestStr++) += ((*vspSourceStr++) - '0');
else if(*vspSourceStr >= 'a' &&am
Linux c 源码(nMAsciiHexToBinary:将16进制字符串格式转换为ASCII码形式)
最新推荐文章于 2021-06-09 18:11:12 发布
该博客介绍了C语言中名为nMAsciiHexToBinary的函数,用于将16进制字符串转换成ASCII码形式。函数首先检查输入字符串长度是否为偶数,然后遍历字符串,根据字符的ASCII值将其转换为16进制数值,并组合成ASCII字符。如果遇到非法字符,函数返回错误码-1。
摘要由CSDN通过智能技术生成