Invert 1 bit in C#

Posted by Matt Jacobsen on Stack Overflow See other posts from Stack Overflow or by Matt Jacobsen
Published on 2010-04-09T08:12:35Z Indexed on 2010/04/09 8:23 UTC
Read the original article Hit count: 521

Filed under:
|
|

I have 1 bit in a byte (always in the lowest order position) that I'd like to invert. ie given 00000001 I'd like to get 00000000 and with 00000000 I'd like 00000001.

I solved it like this:

bit > 0 ? 0 : 1;

I'm curious to see how else it could be done.

© Stack Overflow or respective owner

Related posts about bit-manipulation

Related posts about .NET