当前位置:首页 > Python教程 > python技巧

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 5void show_byte(char_format type, int length) {
 6 7int i;
 8for (i = 0; i < length; i++) {
 9         fprintf(stdout, "%2.x ",  type[i]);
10    }
11     fprintf(stdout, "n");
12}
1314int main(int argc, charconst *argv[]) {
1516int num = 0x12345678;
1718     fprintf(stdout, "%x : ",  num);
19     show_byte((char_format)&num, sizeof(num));
2021return0;
22 }

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

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

原文:http://www.cnblogs.com/jaw-crusher/p/4067581.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐