How to reverse bit: 1 to 0, 0 to 1

How can I reverse/toggle bit like 1 to 0 and conversely, 0 to 1?
For instance: 01000100 ('D' 68) to 10111011 ('╗' 187).
I think it is a great way to encode my game's data. Thanks.

Is there any way easier and more simple than:
1. Convert char/string to binary.
2. Toggle bits.
3. Convert binary back to char/string.
Last edited on
Bitwise unary operator ~
Topic archived. No new replies allowed.