Skip to main content
edited tags
Link
doppelgreener
  • 1.3k
  • 17
  • 26
Source Link
Mateen Ulhaq
  • 973
  • 3
  • 11
  • 22

Bitwise-OR vs Adding Flags

I've seen others use Bitwise-OR to combine flags before:

#define RUN 0x01
#define JUMP 0x02
#define SHOOT 0x04

const byte madPerson = RUN | JUMP | SHOOT;

That's also the way I do it.

But I've also seen some (not as many) combine flags using addition:

#define RUN 0x01
#define JUMP 0x02
#define SHOOT 0x04

const byte madPerson = RUN + JUMP + SHOOT;

Which one is more "readable"? (Which one do you think more people will recognize?) What is the "standard" way to do it? Which one do you prefer?