我正在尝试获取 b'\x00\x00\x00\x01' 的整数值,我假设应该是 1。
我已经尝试了几种方法来获得“1”这个值,但我得到的数字非常高。
这是我尝试过的:
import struct
from struct import *
#I had 4 int values:
byte1 = 0
byte2 = 0
byte3 = 0
byte4 = 1
#I packed each to one byte (seems weird, one int to 1 byte - so is this correct?)
byte1 = struct.pack('b', byte1) #returns b'\x00'
byte2 = struct.pack('b', byte2)
byte3 = struct.pack('b', byte3)
byte4 = struct.pack('b', byte4) #returns b'\x01'
#Now i place all those bytes in one container
con = byte1+byte2+byte3+byte4 #returns …
Run Code Online (Sandbox Code Playgroud)