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‘
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‘\x01\x00\x00\x00‘
>>>
>>> a = array.array(‘l‘,[255]) >>> bytes(a) b‘\xff\x00\x00\x00‘
>>>
>>>
>>> a = array.array(‘l‘,[65535]) >>>
>>> bytes(a) b‘\xff\xff\x00\x00‘
>>>
>>>
低位在低地址内保存,本机使用的是小端模式。