我想将60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00 二进制
以2进制的形式存入byte里面去如byte[] data =new byte[1024];
现在如何将60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00
存进入?存进去表示也是60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00
以2进制的形式存入byte里面去如byte[] data =new byte[1024];
现在如何将60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00
存进入?存进去表示也是60 00 03 00 05 00 07 08 00 20 38 00 00 00 00 00 1e 35 00 00
private static byte[] strToToHexByte(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
//converter hex string to byte and byte to hex string
public static string ByteToString(byte[] InBytes) {
string StringOut="";
foreach (byte InByte in InBytes) {
StringOut=StringOut + String.Format("{0:X2} ",InByte);
}
return StringOut;
}
public static byte[] StringToByte(string InString) {
string[] ByteStrings;
ByteStrings = InString.Split(" ".ToCharArray());
byte[] ByteOut;
ByteOut = new byte[ByteStrings.Length];
for (int i = 0;i<=ByteStrings.Length-1;i++) {
ByteOut[i] = Convert.ToByte(("0x" + ByteStrings[i]),16);
}
return ByteOut;
}
}
这个不是字符串就是byte我存在里面也是byte显示,我现在该怎么存?
byte[] data = strToToHexByte(str); private static byte[] strToToHexByte(string hexString)
{
hexString = hexString.Replace(" ", "");
if ((hexString.Length % 2) != 0)
hexString += " ";
byte[] returnBytes = new byte[hexString.Length / 2];
for (int i = 0; i < returnBytes.Length; i++)
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
return returnBytes;
}
byte[] buffer = new byte[] {0x00,0xFF,0x2F,0x00 };
这样?