zoukankan      html  css  js  c++  java
  • Python如何获取系统大小端模式

    1. 第一种方法导入sys模块;

    >>> import sys
    >>>
    >>> sys.byteorder
    'little'
    >>>

    2. 第二种方法,使用array模块,将整数用signed integer 4字节表示:

        |      Type code   C Type             Minimum size in bytes
        |      'b'         signed integer     1
        |      'B'         unsigned integer   1
        |      'u'         Unicode character  2 (see note)
        |      'h'         signed integer     2
        |      'H'         unsigned integer   2
        |      'i'         signed integer     2
        |      'I'         unsigned integer   2
        |      'l'         signed integer     4
        |      'L'         unsigned integer   4
        |      'q'         signed integer     8 (see note)
        |      'Q'         unsigned integer   8 (see note)
        |      'f'         floating point     4
        |      'd'         floating point     8

    >>> import array
    >>> a = array.array('l',[1])
    >>>
    >>> bytes(a)
    b'x01x00x00x00'
    >>>
    >>> a = array.array('l',[255])
    >>> bytes(a)
    b'xffx00x00x00'
    >>>
    >>>
    >>> a = array.array('l',[65535])
    >>>
    >>> bytes(a)
    b'xffxffx00x00'
    >>>
    >>>

    低位在低地址内保存,本机使用的是小端模式。

  • 相关阅读:
    python程序设计练习题:电子银行购物商城
    python -m参数
    Python 中的 if __name__ == 'main' 的作用和原理
    Modbus协议
    Python configparser模块
    Python logging 模块:日志处理
    python hashlib模块
    Python time模块:Python 日期和时间
    mac 使用系统的自带的quickTime录屏
    Linphone android3.2.4 采用率设置(模拟电话大网信道)
  • 原文地址:https://www.cnblogs.com/frisk/p/11616149.html
Copyright © 2011-2022 走看看