以缓冲区RcvBuf为例:
unsigned char RcvBuf[100];
unsigned int a;
unsigned long b;
unsigned char offset;
...
offset = 0;
a = RcvBuf[offset];
offset++;
a <<= 8;
a |= RcvBUf[offset];
offset++;
b = RcvBuf[offset];
offset++;
b <<= 8;
b |= RcvBuf[offset];
offset++;
b <<= 8;
b |= RcvBuf[offset];
offset++;
b <<= 8;
b |= RcvBuf[offset];
offset++;
...
如果你的字节流是如此排列:
int long int long int long int long int long...
那么可以用个for循环批量赋值
for(i = 0; i < XXX; i++)
{
XXX = (((STRUCT_X *)(void *)Temp)[i]).x;
XXX = (((STRUCT_X *)(void *)Temp)[i]).y;
}