写一程序,判断运行程序的系统是大字节序还是小字节序?写函数实现大小字节序转换
#include <stdio.h>
#include <netinet/in.h>
int main()
{
int i_num = 0x12345678;
printf("[0]:0x%x\n", *((char *)&i_num + 0));
printf("[1]:0x%x\n", *((char *)&i_num + 1));
printf("[2]:0x%x\n", *((char *)&i_num + 2));
printf("[3]:0x%x\n", *((char *)&i_num + 3));
i_num = htonl(i_num);
printf("[0]:0x%x\n", *((char *)&i_num + 0));
printf("[1]:0x%x\n", *((char *)&i_num + 1));
printf("[2]:0x%x\n", *((char *)&i_num + 2));
printf("[3]:0x%x\n", *((char *)&i_num + 3));
return 0;
}