I am using Python 3.6 and I need to convert an integer to a list of individual bits. For example, if I have:
def bitstring_to_bytes(s):
return int(s, 8).to_bytes(8, byteorder='big')
command_binary = format(1, '08b')
bin_to_byte = bitstring_to_bytes(command_binary)
This currently outputs b'\x00\x00\x00\x00\x00\x00\x00\x01'.
But I need to have in a list of integers (but in a hex type format) like so [0x00, 0x00 ... 0x01] in order to pass it to another function. I am stuck at this part.
list(bin_to_byte)would give you a list of integers, is that what you want? You won't see[0x00, ...]because that's not how integers are represented in output, although that's a valid literal form.map(int, bin(str(num))[2:]).list(map(hex, tuple(s)))-->['0x0', '0x0', ..., '0x1']list(b'\x00\x00\x00\x00\x00\x00\x00\x01'). So if that isn't what you want, then you need to tell us exactly what that is.