How to use enums with bit flags

Viewed 11692

I have an enum declaration using bit flags and I cant exactly figure out on how to use this.

enum 
{
  kWhite   = 0,
  kBlue    = 1 << 0,
  kRed     = 1 << 1,
  kYellow  = 1 << 2,
  kBrown   = 1 << 3,
};
typedef char ColorType;

I suppose to store multiple colors in one colorType I should OR the bits together?

ColorType pinkColor = kWhite | kRed;

But suppose I would want to check if pinkColor contains kRed, how would I do this?

Anyone care to give me an example using the provided ColorType example ?

1 Answers
Related