由于经常会用到Str和Hex的互转,所以直接将这两个功能封装成了2个函数,方便使用。写在这里,也便于日后查找使用。
#include <string.h>
/*************************************************************
功 能:将单个字符转换为十六进制数据,例如 'A' -- 0xA, 'C' -- '0xC'
参 数:Arg1:chValue, 待转化的原始字符值;
参 数:Arg2:lpRes, 保留结果的字符指针;
返回值:转换成功返回 true,否则返回 false。
*************************************************************/
bool Char2Hex(unsigned char chValue, unsigned char *lpRes)
{
bool bRet = true;
if(!lpRes)
{
bRet = false;
goto SAFE_EXIT;
}//end if(!lpRes)
if(chValue >= '0' && chValue <= '9')
{
*lpRes = chValue - '0';
goto SAFE_EXIT;
}//end if(chValue >= '0' && chValue <= '9')
else if(chValue >= 'A' && chValue <= '