判别linux机器字节序为大端还是小端

代码如下:

 1 #include <iostream>
 2 #include <arpa/inet.h>
 3 #include <cstdio>
 4 
 5 using namespace std;
 6 
 7 int main(){
 8 
 9     short s=1;
10     if(s == htons(s))cout<<"大端"<<endl;
11     else cout<<"小端"<<endl;
12 
13     return 0;
14 }

 

posted @ 2016-05-09 16:55  hu983  阅读(2911)  评论(0编辑  收藏  举报