16,472
社区成员
发帖
与我相关
我的任务
分享
short int HexChar2Dec(char c)
{
if ( '0'<=c && c<='9' ) {
return short(c-'0');
} else if ( 'a'<=c && c<='f' ) {
return ( short(c-'a') + 10 );
} else if ( 'A'<=c && c<='F' ) {
return ( short(c-'A') + 10 );
} else {
return -1;
}
}
int str2Num16(const char* str)
{
return (str[i+1] == '\0') ? HexChar2Dec(str[i]) : HexChar2Dec(str[i])*16+HexChar2Dec(str[i+1]);
}
void Parse()
{
char hexstr[] = "1A023b4d5c6f9";
int len = (strlen(hexstr)%2 == 0) ? strlen(hexstr)/2 : (strlen(hexstr)/2+1);
unsigned char hex[128] = {0};
for (int i = 0; i < len; ++i)
{
int idx = i*2;
hex[i] = str2Num16(hexstr+idx);
}
}
CString str(_T("1A023b4d5c6f9"));
CString sTemp = str;
int nlen = str.GetLength()/2;\\考虑这个能否整除
char *Buf = new char[nlen];
ZeroMemory(Buf,nlen);
for (int i =0;i<nlen;i++)
{
sTemp.GetBufferSetLength(2);
Buf =(char) _wtoi(sTemp);
str.Delete(0,2);
sTemp.ReleaseBuffer();
}
CString str(_T("1A023b4d5c6f9"));
char tmp[7];
char arr[2];
int j = 0;
int k = 0;
for(int i=0; i<str.GetLength(); i++)
{
if (j == 0)
{
arr[j] = str.GetAt(i);
j = 1;
}
else
{
arr[j] = str.GetAt(i);
int tempNum = atoi(arr);
tmp[k] = tempNum/10*16 + tempNum%10;
k++;
j = 0;
}
}
tmp[6] = '\0';
CString str(_T("1A023b4d5c6f9"));
char tmp[6];
char arr[2];
int j = 0;
int k = 0;
for(int i=0; i<str.GetLength(); i++)
{
if (j == 0)
{
arr[j] = str.GetAt(i);
j = 1;
}
else
{
arr[j] = str.GetAt(i);
int tempNum = atoi(arr);
tmp[k] = tempNum/10*16 + tempNum%10;
k++;
j = 0;
}
}