i have hex list like this ['0x1', '0x3', '0x2', '0x0', '0x0', '0x10', '0x4', '0x0', '0x0', '0xfa', '0x4']
and i intend to send it over USB, so i need to convert into a bytearray, is there a way available in python?
i have hex list like this ['0x1', '0x3', '0x2', '0x0', '0x0', '0x10', '0x4', '0x0', '0x0', '0xfa', '0x4']
and i intend to send it over USB, so i need to convert into a bytearray, is there a way available in python?
That can be solved by a simple one line expression
input = ['0x1', '0x3', '0x2', '0x0', '0x0', '0x10', '0x4', '0x0', '0x0', '0xfa', '0x4']
result = bytes([int(x,0) for x in input])
The result is
b'\x01\x03\x02\x00\x00\x10\x04\x00\x00\xfa\x04'
If you do not actually want to have a byte array, but an array of integers, just remove the bytes()
result = [int(x,0) for x in input]
The result is
[1, 3, 2, 0, 0, 16, 4, 0, 0, 250, 4]