# inverse binary string bit by bit

if i have a binary string for example x='0110101' and i need to inverse it's bits bit by bit. for example : inverse 1st bit >> x='1110101' inverse 2nd bit >> x='0010101' 3rd bit >> x='0100101'

and so on. how can i do that.

This looks like homework. Could you please tell us how it is related to Sage, and what were your attempts in solving this ? For example, why are you using a string and not a list of integers ?

no it is not a homework. it is related to sage as for example i am working with cryptography >> Rijndael-GF block cipher which sometimes i need to use binary key, message and ciphers. anyway i've found a function that do this role as following; # toggleBit() returns an integer with the bit at 'offset' inverted, 0 -> 1 and 1 -> 0.

def toggleBit(int_type, offset): mask = 1 << offset return(int_type ^ mask)