假设aBuf指向一段内存:
BYTE* aBuf
我们要获取里面的数据,可如下获取:
char 型数据:
BYTE ClassID=*(aBuf+len);
stDate=(short)(*((char*)(aBuf+len)));
short ,int16型数据:
stDate=(short)htons(*((short*)(aBuf+len)));
int32 型数据:
lDate=(long)htonl(*((long*)(aBuf+len)));
本文介绍了如何从内存中读取不同类型的数据,包括char、short、int16、int32等基本类型,并提供了具体的C/C++代码示例,展示了如何使用指针和类型转换来正确读取这些数据。
假设aBuf指向一段内存:
BYTE* aBuf
我们要获取里面的数据,可如下获取:
char 型数据:
BYTE ClassID=*(aBuf+len);
stDate=(short)(*((char*)(aBuf+len)));
short ,int16型数据:
stDate=(short)htons(*((short*)(aBuf+len)));
int32 型数据:
lDate=(long)htonl(*((long*)(aBuf+len)));

被折叠的 条评论
为什么被折叠?