请求大家帮助,输出的结果只有第一个是正确的呀?????
#include "stdio.h"#include<string.h>
#include <stdlib.H>
unsigned int wchar1[30];
////////////////////////////////
int gsmString2Bytes( unsigned char* pSrc, unsigned int* pDst, int nSrcLength)
{
int i=0;
for(i=0;i<nSrcLength;i+=4);
{ if(*pSrc >='0' && *pSrc<='9')
{
*pDst = (*pSrc - '0') << 12;
}
else
{
*pDst = (*pSrc - 'A' + 10) << 12;
}
pSrc++;
if(*pSrc>='0' && *pSrc<='9')
{
*pDst |=(unsigned int)(( *pSrc - '0')<<8);
}
else
{
*pDst |=(unsigned int) ((*pSrc - 'A' + 10)<<8);
}
pSrc++;
if (*pSrc >='0' && *pSrc<='9')
{
*pDst |= (unsigned int)((*pSrc - '0') << 4); //|在等号左边时后面不能是空格否则编译错误
}
else
{
*pDst |= (unsigned int)((*pSrc - 'A' + 10) << 4);
}
pSrc++;
if(*pSrc>='0' && *pSrc<='9')
{
*pDst |= *pSrc - '0';
}
else
{
*pDst |= *pSrc - 'A' + 10;
}
pSrc++;
pDst++;
}
return nSrcLength / 4;
}
//////////////////////////////////
int main(void)
{
int tt,kk;
int bb;
char *str="A85B9E2CAB35D56C031B";
kk=strlen(str);
bb= gsmString2Bytes(str,wchar1,kk);
for(tt=0;tt<bb;tt++)
{printf("integer = %x\n",wchar1[tt]);}
return 0;
}
结果输出:
integer =a5b8
integer =0
integer =0
integer =0
integer =0
希望的结果是:
integer =a5b8
integer =9e2c
integer =ab35
integer =d56c
integer =031b