我有一个关于Python3的问题。我已经尝试了几天来创建一个byte对象,如下所示:
b"'\x10\x00\x0020180425"
第一部分“\x10\x00\x00”是两个组合的int16对象。我试着把它们结合起来:
array = [0,0,0,0,1,9,7,0,0,1,0,1]
blebytes = bytearray(array)
z = np.int16(20)
blebytes[0] = (z & 0xFF00) >> 8
blebytes[1] = (z & 0x00FF)
z = np.int16(123)
blebytes[2] = (z & 0xFF00) >> 8
blebytes[3] = (z & 0x00FF)
第二部分(20180425)只是今天的日期。我试着这样做:
datestr = time.strftime("%Y%m%d")
for i in range(0,8):
blebytes[i+4] = np.int16(datestr[i])
print(blebytes)
但是如果我打印blebytes数组,它看起来是这样的:
bytearray(b'\x04\xe8\t\xf7\x02\x00\x01\x08\x00\x04\x02\x05')
我做错什么了?有人能帮我吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐