byte数组之间的赋值,byte和TCHAR数组的赋值
2013-05-10 20:52
295 查看
第一步很关键,给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 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数组之间的赋值,byte和TCHAR数组的赋值
- [原]深入 JAVA里面关于byte数组和String之间的转换问题
- C# 字符串string和内存流MemoryStream及比特数组byte[]之间相互转换
- Java 十六进制(Hex)与byte数组之间的转换
- byte数组和String之间的相互转换代码
- java整数和byte数组之间的转换
- Java基本类型与byte数组之间相互转换
- byte[]数组和int之间的转换
- byte[]数组和int之间的转换
- Java 中 byte、byte 数组和 int、long 之间的转换
- Java 中 byte、byte 数组和 int、long 之间的转换
- Java 中 byte、byte 数组和 int、long 之间的转换
- JAVA里面关于byte数组和String之间的转换问题
- 关于字符串和byte数组在java和ios之间兼容的解决办法
- Android学习 之 Bitmap Drawable byte[] 三者之间的转换以及把数组存入数据库及提取数据重新组合成所需对象,如图像
- java整数和byte数组之间的转换
- JAVA中int型数据和byte数组之间的相互转换
- Java 中 byte、byte 数组和 int、long 之间的转换
- 文件和byte数组之间相互转换
- Java 中 byte、byte 数组和 int、long 之间的转换