C# 将二个字节拼接成有符号输出

C# 将二个字节拼接成有符号输出

接受时

string inputnumber = "42"
short number = inputnumber .	ToShort;
byte[] numberBytes = BitConverter.GetBytes(number)[1];//高字节
byte[] numberBytes2 = BitConverter.GetBytes(number)[0];//低字节

发送时

byte[] bytes = new byte[2]{0x31,0x32};
short u16;
u16 = (short)((bytes[0] << 8) + bytes[1]);
button1.Text = u16.ToString();

你可能感兴趣的:(嵌入式,C#,c#,开发语言)