Hallo Zusammen ich suche eine Möglichkeit mit Python einen Zahlen String in ein Hex Byte Format umzuwandeln. String = '24231111' zu b'\x11\x11\x23\x24'
1 | word = '24231111' |
2 | |
3 | digits = [int(c) for c in word] |
4 | print(digits) |
5 | zero_padded_BCD_digits = [format(d, '04b') for d in digits] |
6 | print(zero_padded_BCD_digits) |
7 | t = ''.join(zero_padded_BCD_digits) |
8 | print(t) |
9 | hexStringResult = hex(int(t, 2)) |
10 | print(hexStringResult) |
11 | print(type(hexStringResult)) |
Ausgabe =
1 | [2, 4, 2, 3, 1, 1, 1, 1] |
2 | ['0010', '0100', '0010', '0011', '0001', '0001', '0001', '0001'] |
3 | 00100100001000110001000100010001 |
4 | 0x24231111 |
bin über Hilfe dankbar grüsse Joel