写一程序,判断运行程序的系统是大字节序还是小字节序?写函数实现大小字节序转换

#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;
}

 



posted @ 2017-03-31 10:46  我有一壶酒  阅读(962)  评论(0编辑  收藏  举报