四种方法:
short BLC(short s)
{
byte high = (byte)((s - s % 256) / 256); //数字减去 低8位, 得到的数字再除以256得到高8位
byte low = (byte)(s % 256); //数字对256取余数, 得到低8位
byte[] change1 = { high, low };
return BitConverter.ToInt16(change1);
}
short BLC2(short s)
{
byte[] bytes = BitConverter.GetBytes(s);
Array.Reverse(bytes);
return BitConverter.ToInt16(bytes, 0);
}
short BLC3(short s)
{
byte highByte = (byte)(s >> 8); // 右移8位获取高字节
byte lowByte = (byte)(s & 0xFF); // 与16位,高8位是0, 低8位是11111111
byte[] bytes = { highByte, lowByte };
return BitConverter.ToInt16(bytes);
}
short BLC4(short s)
{
byte[] bytes = BitConverter.GetBytes(s);
return BitConverter.ToInt16([bytes[1], bytes[0]]);
}
结果: