Bitwise Operations

Q

Which bit wise operator is suitable for turning off a particular bit in a number?

✍: FYIcenter

A

The bitwise AND operator. Here is an example:

enum {
   KBit1 = 0x00000001
   KBit2 = 0x00000010,
   KBit3 = 0x00000100,
   ...
};
some_int = some_int & ~KBit24;

2007-02-26, 9484👍, 0💬