其实库中已经有对于双字节和四字节高低字节倒序的函数,非常方便,使用如下:
1.包含头文件
Windows系统 #include<Winsock2.h>
linux系统 #include <arpa/inet.h>
2.包含WS2_32.LIB(Project-->Setting-->Object/library modules)
3.使用
3-1如果想把双字节数高低字节反转使用下面函数:
u_short PASCAL FAR ntohs (u_short netshort);
USHORT s = 0x1234;
s = ntohs (s);
printf("%X\n", s);
打印输出:0x3412
3-2如果想把四字节数高低字节反转使用下面函数:
u_long PASCAL FAR ntohl (u_long netlong);
DWORD w = 0x12345678;
w = ntohl (w);
printf("%X\n", w);
打印输出:0x78563412