Most common C# bitwise operations
Posted
by steffenj
on Stack Overflow
See other posts from Stack Overflow
or by steffenj
Published on 2008-09-18T15:46:20Z
Indexed on
2010/05/15
22:40 UTC
Read the original article
Hit count: 392
For the life of me, I can't remember how to set, delete, toggle or test a bit in a bitfield. Either I'm unsure or I mix them up because I rarely need these. So a "bit-cheat-sheet" would be nice to have.
For example:
flags = flags | FlagsEnum.Bit4; // Set bit 4.
or
if ((flags == FlagsEnum.Bit4)) == FlagsEnum.Bit4) // Is there a less verbose way?
Can you give examples of all the other common operations, preferably in C# syntax using a [Flags] enum?
© Stack Overflow or respective owner