我正在使用一种专有协议,该协议将整数作为 16 位二进制补码分两部分传输。首先发送 LSB,然后发送 MSB。以下代码恢复原始值是否正确?
unsigned char message[BLK_SIZE];
// read LSB to message[0] and MSB to message[1]
short my_int = (message[1] << 8) | message[0];
我正在使用一种专有协议,该协议将整数作为 16 位二进制补码分两部分传输。首先发送 LSB,然后发送 MSB。以下代码恢复原始值是否正确?
unsigned char message[BLK_SIZE];
// read LSB to message[0] and MSB to message[1]
short my_int = (message[1] << 8) | message[0];