直接上代码:
1 int CDlgPump::ChangeNum(CString str,int length)
2 {
3 char revstr[16] = {0}; //根据十六进制字符串的长度,这里注意数组不要越界
4 int nNum[16] = {0};
5 int nCount = 1;
6 int nResult = 0;
7
8 strcpy_s(revstr, str);
9
10 for(int i = length-1; i>= 0; i--)
11 {
12 if ((revstr[i] >= '0') && (revstr[i]<='9'))
13 nNum[i] = revstr[i] -48; //字符0的ASCII值为48
14 else if ((revstr[i] >= 'a') && (revstr[i] <= 'f'))
15 nNum[i] = revstr[i] - 'a' +10;
16 else if ((revstr[i] >= 'A') && (revstr[i] <= 'F'))
17 nNum[i] = revstr[i] - 'A' + 10;
18 else
19 nNum[i] = 0;
20 nResult = nResult+nNum[i]*nCount;
21 nCount = nCount*16; //十六进制(如果是八进制就在这里乘以8)
22 }
23 return nResult;
24 }
2 {
3 char revstr[16] = {0}; //根据十六进制字符串的长度,这里注意数组不要越界
4 int nNum[16] = {0};
5 int nCount = 1;
6 int nResult = 0;
7
8 strcpy_s(revstr, str);
9
10 for(int i = length-1; i>= 0; i--)
11 {
12 if ((revstr[i] >= '0') && (revstr[i]<='9'))
13 nNum[i] = revstr[i] -48; //字符0的ASCII值为48
14 else if ((revstr[i] >= 'a') && (revstr[i] <= 'f'))
15 nNum[i] = revstr[i] - 'a' +10;
16 else if ((revstr[i] >= 'A') && (revstr[i] <= 'F'))
17 nNum[i] = revstr[i] - 'A' + 10;
18 else
19 nNum[i] = 0;
20 nResult = nResult+nNum[i]*nCount;
21 nCount = nCount*16; //十六进制(如果是八进制就在这里乘以8)
22 }
23 return nResult;
24 }