Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
a'&';在python bytearray中代表_Python_Arrays_Python 3.x - Fatal编程技术网

a'&';在python bytearray中代表

a'&';在python bytearray中代表,python,arrays,python-3.x,Python,Arrays,Python 3.x,在pythonbytearray的末尾,符号和是什么意思 e、 g: 将其转换为整数时 int.from_bytes(x_w, 'little') Out[1]: 2743275644678045696 它给出了与不带“&”的同一bytearray不同的结果: x_wo = bytearray(b'\x00\x00\x04\x12\xaa\x12\x12') int.from_bytes(x_wo, 'little') Out[2]: 5087071236784128 我查过了,但没有找

在python
bytearray
的末尾,符号和是什么意思

e、 g:

将其转换为整数时

int.from_bytes(x_w, 'little')

Out[1]: 2743275644678045696
它给出了与不带“&”的同一bytearray不同的结果:

x_wo = bytearray(b'\x00\x00\x04\x12\xaa\x12\x12')
int.from_bytes(x_wo, 'little')

Out[2]: 5087071236784128

我查过了,但没有找到答案。谢谢

它只是用值
26
(十进制38)表示字节,这是ASCII中的
“&
字符

如果打印所用字节文字的实际字节值,则可以清楚地看到:

打印(“”.join(“%02x”%b代表b中的b'\x00\x00\x04\x12\xaa\x12\x12&')) 00 00 04 12 aa 12 12 26 而
bytearray
对象的
repr
尽可能倾向于使用ASCII字符而不是十六进制转义来表示字节。因此,它更倾向于表示
'&
而不是
'\x26'
,即使它们在技术上是等效的:

字节数组([0x00、0x00、0x04、0x12、0xAA、0x12、0x12、0x12、0x26]) bytearray(b'\x00\x00\x04\x12\xaa\x12\x12&')) >>>b'\x26'==b'&' 真的
它只是一个角色。更改为big-endian,您将得到
0x‭412AA121226‬
0x26
的字符代码。
x_wo = bytearray(b'\x00\x00\x04\x12\xaa\x12\x12')
int.from_bytes(x_wo, 'little')

Out[2]: 5087071236784128