Ist das ein Bug?
RU = (249, 253, 12, 100, 11, 36, 129, 68, 206, 4, 139, 157)
bytearray(RU)
bytearray(b'\xf9\xfd\x0cd\x0b$\x81D\xce\x04\x8b\x9d')
Da hat es ein d und ein$ zuviel?
M.f.G. Pascal
Bytearray
- __blackjack__
- User
- Beiträge: 14326
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
Veranschaulichung in einer Python-Shell:
Code: Alles auswählen
In [11]: values = [249, 253, 12, 100, 11, 36, 129, 68, 206, 4, 139, 157]
In [12]: binary = bytearray(values)
In [13]: binary
Out[13]: bytearray(b'\xf9\xfd\x0cd\x0b$\x81D\xce\x04\x8b\x9d')
In [14]: list(binary)
Out[14]: [249, 253, 12, 100, 11, 36, 129, 68, 206, 4, 139, 157]
In [15]: list(binary) == values
Out[15]: True
In [16]: bytearray([36])
Out[16]: bytearray(b'$')
In [17]: ord("$")
Out[17]: 36
In [18]: chr(36)
Out[18]: '$'„Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.“ — Brian W. Kernighan
-
pascal.buehler
- User
- Beiträge: 12
- Registriert: Dienstag 5. Oktober 2021, 08:32
Ja stimmt, danke.
-
pascal.buehler
- User
- Beiträge: 12
- Registriert: Dienstag 5. Oktober 2021, 08:32
Aber sollte das nicht durchgängig immer gleich sein? Es ist nur verwirrend?
Eine übersichtliche hexadezimale Darstellung kann man so erhalten:
Code: Alles auswählen
" ".join(map("{:02X}".format, byte_values))- __blackjack__
- User
- Beiträge: 14326
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@snafu: Das gibt's schon fertig als Methode auf `bytearray` (und `bytes`):
Code: Alles auswählen
In [29]: data = bytearray(b'\xf9\xfd\x0cd\x0b$\x81D\xce\x04\x8b\x9d')
In [30]: data.hex()
Out[30]: 'f9fd0c640b248144ce048b9d'
In [31]: data.hex(" ")
Out[31]: 'f9 fd 0c 64 0b 24 81 44 ce 04 8b 9d'„Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.“ — Brian W. Kernighan
