Python 得到主机字节序

  使用Python可以很快得到一些系统的信息,比如平台,字节序,和Python最大递归限制,比如:

 

import sys

# get byte order
print sys.byteorder

# get platform 
print sys.platform

# nothing to say ^_^
print sys.getrecursionlimit()

关于字节序可以使用以下的C代码验证:

 1 #include <stdio.h>
 2 
 3 typedef unsigned char * char_format;
 4 
 5 void show_byte(char_format type, int length) {
 6 
 7     int i;
 8     for (i = 0; i < length; i++) {
 9         fprintf(stdout, "%2.x ",  type[i]);
10     }
11     fprintf(stdout, "\n");
12 }
13 
14 int main(int argc, char const *argv[]) {
15 
16     int num = 0x12345678;
17     
18     fprintf(stdout, "%x : ",  num);
19     show_byte((char_format)&num, sizeof(num));
20 
21     return 0;
22 }

小端序是权值低的在前面,大端序是权值高的在前面。

比如0x12345678在小端序下 是按照78 56 34 21存储的,而大端序是按照 12 34 56 78 存储的。

posted @ 2014-11-01 18:45  jaw-crusher  阅读(605)  评论(0编辑  收藏  举报