#include <iostream>
#include <windows.h>
using namespace std;
//十六进制字符串转换成十进制整数
int StringToInt(CHAR *szSource)
{
int iBuffer[64] ={0};
int i = 0;
int nLen = strlen(szSource);
int iNumber = 0;
int k = 0;
for( i=nLen-1;i>=0;i--)
{
int iResult = 1;
for(int j=1;j<= i;j++)
{
iResult =iResult*16;
}
switch(szSource[k++])
{
case '0':
iBuffer[i] = 0*iResult;
break;
case '1':
iBuffer[i] = 1*iResult;
break;
case '2':
iBuffer[i] = 2*iResult;
break;
case '3':
iBuffer[i] = 3*iResult;
break;
case '4':
iBuffer[i] = 4*iResult;
break;
case '5':
iBuffer[i] = 5*iResult;
break;
case '6':
iBuffer[i] = 6*iResult;
break;
case '7':
iBuffer[i] = 7*iResult;
break;
case '8':
iBuffer[i] = 8*iResult;
break;
case '9':
iBuffer[i] = 9*iResult;
break;
case 'A':
iBuffer[i] = 10*iResult;
break;
case 'B':
iBuffer[i] = 11*iResult;
break;
case 'C':
iBuffer[i] = 12*iResult;
break;
case 'D':
iBuffer[i] = 13*iResult;
break;
case 'E':
iBuffer[i] = 14*iResult;
break;
case 'F':
iBuffer[i] = 15*iResult;
break;
case 'a':
iBuffer[i] = 10*iResult;
break;
case 'b':
iBuffer[i] = 11*iResult;
break;
case 'c':
iBuffer[i] = 12*iResult;
break;
case 'd':
iBuffer[i] = 13*iResult;
break;
case 'e':
iBuffer[i] = 14*iResult;
break;
case 'f':
iBuffer[i] = 15*iResult;
break;
}
iNumber += iBuffer[i];
}
return iNumber;
#include <windows.h>
using namespace std;
//十六进制字符串转换成十进制整数
int StringToInt(CHAR *szSource)
{
int iBuffer[64] ={0};
int i = 0;
int nLen = strlen(szSource);
int iNumber = 0;
int k = 0;
for( i=nLen-1;i>=0;i--)
{
int iResult = 1;
for(int j=1;j<= i;j++)
{
iResult =iResult*16;
}
switch(szSource[k++])
{
case '0':
iBuffer[i] = 0*iResult;
break;
case '1':
iBuffer[i] = 1*iResult;
break;
case '2':
iBuffer[i] = 2*iResult;
break;
case '3':
iBuffer[i] = 3*iResult;
break;
case '4':
iBuffer[i] = 4*iResult;
break;
case '5':
iBuffer[i] = 5*iResult;
break;
case '6':
iBuffer[i] = 6*iResult;
break;
case '7':
iBuffer[i] = 7*iResult;
break;
case '8':
iBuffer[i] = 8*iResult;
break;
case '9':
iBuffer[i] = 9*iResult;
break;
case 'A':
iBuffer[i] = 10*iResult;
break;
case 'B':
iBuffer[i] = 11*iResult;
break;
case 'C':
iBuffer[i] = 12*iResult;
break;
case 'D':
iBuffer[i] = 13*iResult;
break;
case 'E':
iBuffer[i] = 14*iResult;
break;
case 'F':
iBuffer[i] = 15*iResult;
break;
case 'a':
iBuffer[i] = 10*iResult;
break;
case 'b':
iBuffer[i] = 11*iResult;
break;
case 'c':
iBuffer[i] = 12*iResult;
break;
case 'd':
iBuffer[i] = 13*iResult;
break;
case 'e':
iBuffer[i] = 14*iResult;
break;
case 'f':
iBuffer[i] = 15*iResult;
break;
}
iNumber += iBuffer[i];
}
return iNumber;
}
int main()
{
char * str = "";
cout << StringToInt("aa") << endl;
return 0;
}