技术的乐趣在于分享,欢迎多多交流,多多沟通。
全部博文(877)
分类: IT职场
2014-12-04 13:15:39
#include
#include
#define IN
#define OUT
typedef unsigned char BYTE;
static void sTringToChar(IN BYTE * pbIn, OUT BYTE * pbOut)
{
BYTE bvar,foo;
BYTE temp1,temp2;
strupr(pbIn);
bvar = strlen(pbIn);
for(foo = 0; foo < (bvar >> 1); ++foo)
{
// *(pbOut + foo) = ( ( (*(pbIn + foo * 2) - 0x30) << 4) | ( (*(pbIn + foo * 2 + 1) - 0x30) ) ) ;
if(*(pbIn + foo * 2) < 'A' )
temp1 = (*(pbIn + foo * 2) - 0x30) << 4;
else
temp1 = ( (*(pbIn + foo * 2) - 0x41) + 0x0A) << 4;
if(*(pbIn + foo * 2 + 1) < 'A' )
temp2 = *(pbIn + foo * 2 + 1) - 0x30;
else
temp2 = (*(pbIn + foo * 2 + 1) - 0x41) + 0x0A;
*(pbOut + foo) = temp1 | temp2;
}
}
int main(void)
{
char foo;
char * pcmd = "00A404000E315041592E5359532E4444463031";
char btemp[19] = {0};
// BYTE btemp[19] = {0};
sTringToChar(pcmd, btemp);
for(foo = 0; foo < 19; ++foo)
printf("the btmep is %02x\n",btemp[foo]);
return 0;
}
/*
int main(void)
{
char temp[4] = {0};
BYTE var = (0x01 << 4);
temp[0] = var;
printf("the temp is %02x\n",temp[0]);
}
*/
输出
将
char btemp[19] = {0};改为 BYTE btemp[19] = {0};后正常