Feb-18-2021, 10:44 AM
(This post was last modified: Feb-18-2021, 10:44 AM by deanhystad.)
What is the application for this? About the only time I run into byte arrays is serial ports or sockets. For those applications I would send an array of bytes as an array of bytes, not an array of ASCII codes for bytes. If I was sent an array of bytes encoded like this I would probably use decode() to convert the bytearray to a string, and then process the string. This converts your bytearray to an array of ints.
my_list = b'[1, 0, 1, 1]' my_bin_nums = [int(c) for c in my_list.decode() if c in '01'] print(my_bin_nums, my_bin_nums[1])
Output:[1, 0, 1, 1] 0