十六进制字符串转换成十进制整数的C++实现源代码

来源:互联网 发布:电子书数据库? 编辑:程序博客网 时间:2024/05/14 03:57
int str2Hex( char *pstr){int ans = 0;char *pt;pt = pstr;if( !pstr ){return 0;}while( *pt ){  ans = ans<<4;if( ( *pt >=  'A' && *pt <=  'F' ) || ( *pt >=  'a' && *pt <=  'f' ) ){//cout << ((*pt & 0x5f) -0x37) << endl;//cout << ((0x44 & 0x5f) -0x37) << endl;//0x0D==13ans  = ans | ((*pt & 0x5f) -0x37);}elseans  = ans | (*pt) -0x30;pt++;}return ans;}


 

0 0