I have a list of boolean strings. Each string is of length 6. I need to get the complement of each string. E.g, if the string is "111111", then "000000" is expected. My idea is
bin(~int(s,2))[-6:]
- convert it to integer and negate it by treating it as a binary number
- convert it back to a binary string and use the last 6 characters.
I think it is correct but it is not readable. And it only works for strings of length less than 30. Is there a better and general way to complement a boolean string?
I googled a 3rd party package "bitstring". However, it is too much for my code.