首先定义一个uint8_t类型数组长度为2的uint8_t buf[2]; 而用buf[0]跟buf[1]组合表示1个int16_t的short类型数据.
uint8_t类型的buf[0]跟buf[1]组成int16_t的short类型(-32768~32767)
规律:
1. 当buf[0] = 0;buf[1] = 1; short的数值为256
2. 当buf[0] = 0;buf[1] = 2; short的数值为512
3. 当buf[0] = 1;buf[1] = 0; short的数值为1
4. 当buf[0] = 2;buf[1] = 0; short的数值为2
5. 当buf[0] = 1;buf[1] = 1; short的数值为257
6. 当buf[0] = 2;buf[1] = 1; short的数值为258
7. 当buf[0] = 1;buf[1] = 2; short的数值为513
总结:
int16_t的short的值等于buf[3] * 1 + buf[4] * 256;
且当超过32767后,则再+1则调到-32768开始往前计数