C++ ASCIIToBinary

BYTE AscllToBinary(char ctemp)
{
BYTE result = 0xff;
if (ctemp >= '0' && ctemp <= '9')
{//'0'-'9' 之间的ascll字符
result = ctemp - '0';
return result;
}

if (ctemp >= 'A' && ctemp <= 'F')
{//'0'-'9' 之间的ascll字符
result = ctemp - 'A' + 10;
return result;
}

if (ctemp >= 'a' && ctemp <= 'f')
{//'0'-'9' 之间的ascll字符
result = ctemp - 'a' + 10;
return result;
}
cout<<"字符不是有效的字符十六进制数\n";
//TRACE("字符不是有效的字符十六进制数\n");
return result;//返回ff代表出错了
}

posted @ 2014-09-02 19:02  niupan369  阅读(282)  评论(0编辑  收藏  举报