Ath*_*hos 3 python signed byte
number = -127
array = number.to_bytes( 1 , byteorder='big' , signed=True )
Run Code Online (Sandbox Code Playgroud)
只转换为单个字节
print( array[0] )
number_positive = 254
array = array + number_positive.to_bytes( 1 , byteorder='big' , signed=False )
Run Code Online (Sandbox Code Playgroud)
那我应该如何分别打印-127和254呢
如果我只使用array[0] and array[1]答案将是两个积极的
非常感谢您的帮助 提前谢谢您
您应该使用该int.from_bytes()方法将字节转换回整数:
print(int.from_bytes(array, byteorder='big', signed=True))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17209 次 |
| 最近记录: |