zoukankan      html  css  js  c++  java
  • 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, "
    ");
    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 存储的。

  • 相关阅读:
    UVA 558 Wormholes
    HDU 1565 方格取数(1)
    poj2607
    poj2552
    poj2491
    poj2502
    poj2613
    .NET Framework 4 与 .NET Framework 4 Client Profile的区别与联系
    .Net Framework 4.0 和 2.0/3.0/3.5
    企业IT系统
  • 原文地址:https://www.cnblogs.com/jaw-crusher/p/4067581.html
Copyright © 2011-2022 走看看