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

时间:2016-05-09 17:01:12   收藏:0   阅读:659

代码如下:

 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 }

 

原文:http://www.cnblogs.com/hu983/p/5474568.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!