Если я понять ваш вопрос правильно, это вы должны получить список булевы вы ищете:
text = "\\x00\\x00\\x00\\x00"
# First off, lets convert a byte represented by a string consisting of two hex digits
# into an array of 8 bits (represented by ints).
def hex_byte_to_bits(hex_byte):
binary_byte = bin(int(hex_byte, base=16))
# Use zfill to pad the string with zeroes as we want all 8 digits of the byte.
bits_string = binary_byte[2:].zfill(8)
return [int(bit) for bit in bits_string]
# Testing it out.
print(hex_byte_to_bits("00")) # [0, 0, 0, 0, 0, 0, 0, 0]
print(hex_byte_to_bits("ff")) # [1, 1, 1, 1, 1, 1, 1, 1]
# Use our function to convert each byte in the string.
bits = [hex_byte_to_bits(hex_byte) for hex_byte in text.split("\\x") if hex_byte != ""]
# The bits array is an array of arrays, so we use a list comprehension to flatten it.
bits = [val for sublist in bits for val in sublist]
print(bits) # [0, 0, 0, 0, ...
booleans = [bool(bit) for bit in bits]
print(booleans) # [False, False, False, ...
если вы хотите в hex, используйте '' \ x00 \ x00 \ x00 \ x00 \ '. encode (' hex ') ' –
@JakobWeisblat: Это совсем не то, что хочет OP. Они хотят '[False] * 32' (не 64, как фактически говорит OP, потому что это 8 * 4). – Kevin
@ Kevin это 16 * 4, нет? OP думал 8 восьмеричных цифр, возможно – cxrodgers