18 lines
448 B
C
18 lines
448 B
C
#include <stdio.h>
|
|
#include <arpa/inet.h>
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
unsigned int data = 0x01020304;
|
|
// 转成网络端数据(小端转大端)
|
|
uint32_t data2 = htonl(data);
|
|
printf("主机字节序: %#08x\n", data);
|
|
printf("网络字节序: %#x\n", data2);
|
|
|
|
// 将网络字节序转为主机字节序
|
|
uint32_t data3 = ntohl(data2);
|
|
printf("转换后主机字节序: %#x\n", data);
|
|
|
|
return 0;
|
|
}
|