1.c#与嵌入式定义的字是高字节在前,低字节在后,如0x10 0x01,高字节为0x10,低字节为0x01;c#使用byte[]转出来的数据为0x01 0x10,c#的高字节是在后,低字节在前,取值的时候不能取错;
(1)整形转16进制结果为 四个字节q[1],q[3]为高字节,q[0]和q[2]为低字节;(q[3]0x01 、q[2]0x30为高字)、(q[1]0x43、 q[0]0xDE为低字)
byte[] q=BitConverter.GetBytes(19940318);
(2)byte[]转字符串16进制,注32为十进制值对应的16进制为0x20
byte[] data = new byte[] { 0x30, 0x64, 32 };
var sArray = BitConverter.ToString(data );
sArray 输出结果为30-64-20
(3)string16进制字符串转byte[]
string[] hexValuesSplit = "30-64-20".Split('-');
byte[] data = new byte[hexValuesSplit.Length];
for (int i=0;i< hexValuesSplit.Length;i++) {
data [i] = Convert.ToByte(hexValuesSplit[i], 16);
}
输出结果为0x30、0x64、0x20数组集合
(4)string二进制先改对应的bit,再转对应的byte
char[] charArray =