python中的无符号字节数组

问题描述 投票:-4回答:1

我一直在寻找如何将python中的[[string转换为有符号和无符号字节的数组,然后再次将字节数组转换为字符串的方法。

例如:

s = "sample data" # for example any string bytearray = [8, 28, 61, 26, 124, -4, -27, 87, -99, -13, 94, 115, 23, 85, -5, 123, 52, 93, -127, 75, 79, -100, -75, 126, -51, 45, 91, 46, -114, -66, -18, -26, -123, 34, -110, -60, 39, 100, 109, -95, -8, 29, -20, 13, -22, -116, 86, -27, 97, -56, -115, 28, 68, 8, 50, 63, 105, 77, 68, -86, 63, -8, 59, -59, 91, 48, 2, 82, 65, 118, -107, -88, 49, 65, 5, -27, -16, -61, 8, 47, 76, -110, -46, 71, 80, 70, 108, -115, -101, 29, -32, -34, 100, -101, -108, -42, 76, -56, -45, 39, 25, 59, 45, 17] # should give array of signed and unsigned bytes

python arrays unsigned
1个回答
0
投票
Python本身没有字节,从“ 0”到“ 255”之间的意义上讲,“字节”始终是无符号的。

如果需要“带符号字节”,则需要使用intstruct模块(类型代码array)显式请求这种解析。

© www.soinside.com 2019 - 2024. All rights reserved.