你这是转换为16进制数啊
不过是可以实现的,好在我之前做过,代码在此:
int str16toint(char s[])
{
int i,m,temp=0,n;
m=strlen(s);//十六进制是按字符串传进来的,所以要获得他的长度
for(i=0;i<m;i++)
{
if(s[i]>='A'&&s[i]<='F')//十六进制还要判断他是不是在A-F或者a-f之间a=10。。
n=s[i]-'A'+10;
else if(s[i]>='a'&&s[i]<='f')
n=s[i]-'a'+10;
else n=s[i]-'0';
temp=temp*16+n;
}
return temp;
}
void HextoStr( const char *sSrc, char *sDest, int nSrcLen )
{
int i;
char szTmp[3];
for( i = 0; i < nSrcLen; i++ )
{
sprintf( szTmp, "%02X", (unsigned char) sSrc[i] );
memcpy( &sDest[i * 2], szTmp, 2 );
}
return ;
}
void HexStrToByte(const char* source, unsigned char* dest, int sourceLen)
{
short i;
unsigned char highByte, lowByte;
for (i = 0; i < sourceLen; i += 2)
{
highByte = toupper(source[i]);
lowByte = toupper(source[i + 1]);
if (highByte > 0x39)
highByte -= 0x37;
else
highByte -= 0x30;
if (lowByte > 0x39)
lowByte -= 0x37;
else
lowByte -= 0x30;
dest[i / 2] = (highByte << 4) | lowByte;
}
return ;
}
追问怎么调用呢?举个例子吧,配上参数,谢谢。另外程序报错error C2065: 'toupper' : undeclared identifier
追答toupper()函数的作用是把小写的字母转化为大写,要用这个函数的话要加入相应的头文件
#include
本回答被网友采纳