byte数组之间的赋值,byte和TCHAR数组的赋值

      第一步很关键,给byte数组赋值,

byte tzi[2][44] = 
{
0xD0,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x94,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};必须是以0x的方式开头,表示类型为字节,否则以L“”,这种赋值,会变为ASCII码的形式,

将byte* 赋值给byte* ,利用memcpy(),进行赋值即可。


将TChar*赋值给 byte*

 int StrToBin(TCHAR* inWord, BYTE* OutBin, int source_len)
{
int t;
int t2;
int count = 0;
BYTE temBin[2];
temBin[0] = 1;
temBin[1] = 1;
if (source_len < 1)
return 0;
for(t = 0 ;t < source_len; t ++)
{   
t2 = inWord[t];
if( t2 > 127 )
{
temBin[0] =  t2 >> 8 ;/// 256;
temBin[1] =  t2;
OutBin[count] = temBin[0];
count += 1;
OutBin[count] = temBin[1];
count += 1;
}
else
{
OutBin[count] = t2;
count += 1;
}
}
return count;
}




 

你可能感兴趣的:(byte)