What does an ampersand &
mean at the end of a python bytearray
?
e.g.:
x_w = bytearray(b\'\\x00\\x00\\x04\\x12\\xaa\\x12\\x1
It's simply the representation of the byte with value 26
(decimal 38), which is the '&'
character in ASCII.
If you print the actual byte values of the bytes literal you used, you can see this clearly:
>>> print(' '.join('%02x' % b for b in b'\x00\x00\x04\x12\xaa\x12\x12&'))
00 00 04 12 aa 12 12 26
And the repr
of the bytearray
object prefers to represent bytes using ASCII characters rather than hex escapes whenever possible. So it will prefer the representation '&'
rather than '\x26'
, even though they are technically equivalent:
>>> bytearray([0x00, 0x00, 0x04, 0x12, 0xAA, 0x12, 0x12, 0x26])
bytearray(b'\x00\x00\x04\x12\xaa\x12\x12&')
>>> b'\x26' == b'&'
True