The following code is implemented under VC2008:
one, int type turn 16 into the system CString
CString inttocstringhex (int algorism)//16 Conversion
{
Vector<int> Renum;
CString str;
Reverse output
Todo
{
int ntemp = algorism%16;
ALGORISM=ALGORISM/16;
Renum.push_back (NTEMP);
}while (algorism);
The annotation section is plus 0, and if necessary you can use
while (Renum.size () < 4)
// {
Renum.push_back (0);
// }
Reverse output
for (int i = Renum.size ()-1; I >=0; i.)
{
CString strtemp;
if (renum[i]>=10 && renum[i]<=15)
{
WCHAR ch = ' A ' + renum[i]-10; VC2008 with wchar,vc6.0 should use Char
strtemp = ch;
}
Else
{
Strtemp.format (_t ("%d"), Renum[i]);
}
str = strtemp;
}
return str;
}
two, 16 into the CString int type
int Cstringhextoint (CString str)
{
int nret = 0;
int count = 1;
for (int i = str. GetLength ()-1; I >= 0; I.)
{
int nnum = 0;
Char chtest;
Chtest = str. GetAt (i); CString generally do not have this use, but this program is not a problem
if (chtest >= ' 0 ' && chtest <= ' 9 ')
{
Nnum = chtest-' 0 ';
}
else if (chtest >= ' Á ' && chtest <= ' F ')
{
Nnum = chtest-' A ' + 10;
}
else if (chtest >= ' a ' && chtest <= ' F ')
{
Nnum = chtest-' a ' + 10;
}
Nret + = Nnum*count;
Count *= 16;
}
return nret;
}