Bitwise Operations

Q

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

✍: FYIcenter

A

The bitwise OR operator. In the following code snippet, the bit number 24 is turned ON:

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

2007-02-26, 7355👍, 0💬