1.查帖子偶然看到关于多字节转换,随笔记录小结,代码部分:
private void button1_Click(object sender, EventArgs e)
{
//在 C# 中,BitConverter.ToUInt16 方法将按照小端字节序进行解析。
//因此,在给定字节数组 temp 时,假设其按照小端字节序存储。则 temp[0] 是低位字节,temp[1] 是高位字节。
//byte[] temp = new byte[] { 0x06, 0x01 };
byte[] temp = new byte[] { 0x01, 0x06 };//temp[0]-0x01低位字节 ,temp[1]-0x06高位字节 =>综合就是0x0601==>十进制就是1537
byte[] temp2 = new byte[] { 0x06, 0x01 };//temp[0]-0x06低位字节 ,temp[1]-0x01高位字节 =>综合就是0x0106==>十进制就是262
pvValue[1] = BitConverter.ToUInt16(temp, 0);
pvValue[2] = BitConverter.ToUInt16(temp2, 0);
MessageBox.Show($"{pvValue[1]},{pvValue[2]}");
//var shi1 = Convert.ToInt32("0x0601");//Wrong
//在 C# 中,可以使用 Convert.ToInt32 方法将十六进制字符串转换为整数,例如:
string hexString = "0x0601";
int decimalValue = Convert.ToInt32(hexString, 16);
//这个例子