将16进制表示的数字的字符串转换成数字

来源:百度知道 编辑:UC知道 时间:2024/06/29 22:23:35
比如将
"7A7A"
转换成
31354
需要的是unicode 版本的

摆平了
wchar_t hextowchar(wchar_t *s)
{
int t = 0;
wchar_t temp;
for (int i = 0; i < 4; i++)
{
t *= 0x10;
if (s[i] < 65)
{
t += s[i] - 48;
}
else
{
temp = s[i] & 0xDF;
t += temp - 55;
}
}
return (wchar_t)t;
}
但还是要谢谢你

http://zhidao.baidu.com/question/122708801.html

#include <stdio.h>
#include <string.h>

int str2hex(const char *ch) /* 字符串转16进制数 */
{
int i=0, tmp, result=0;

for(i=0; i<strlen(ch); i++) /* 把字符一个一个转成16进制数 */
{
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;
}

int main(void)
{
char ch[] = "499602D2";
char bufDec[10];
char bufHex[10];
int i=0;
i = str2hex(ch); /* 16进制字符串转成整数 */
/* 反