Is there any build in function in python to convert a bool array (which represents bits in a byte) like so:
p = [True, True, True, False, True, False, False, True]
into a byte array like this:
bp = byteArray([233])
I am aware oh numpy but I was looking for something within python itself
This will do what you want:
sum(v<<i for i, v in enumerate(p[::-1]))
Just use algebra:
sum(2**i for i, v in enumerate(reversed(p)) if v)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With