title: Bitmasking in Objective C
body: <p>I'd like to learn bit masking. As far as I understand, it is means to store binary values of certain type into one variable.</p>
  
  <p>If the above assumption is true, I figured I could do something like this:</p>
  
  <pre><code>typedef NSUInteger Traits;
  
  enum
  {
      TraitsCharacterHonest       = 0,
      TraitsCharacterOptimistic   = 1,
      TraitsCharacterPolite       = 4,
      TraitsCharacterDevious      = 8,
      TraitsPhysicalTall          = 16,
      TraitsPhysicalBeautiful     = 32,
      TraitsPhysicalFat           = 64,
      TraitsPhysicalBigEyes       = 128,
      TraitsPhysicalRedHair       = 256, 
  };
  
  #import &lt;Foundation/Foundation.h&gt;
  
  @interface Person : NSObject
  
  @property (strong, nonatomic) NSString  *name;
  @property (assign, nonatomic) Traits    *traits;
  
  @end
  </code></pre>
  
  <p><strong>Question 1</strong> is, how do I assign more traits to one person?</p>
  
  <p><strong>Question 2</strong> is, do I have to put ever increasing numbers to enum items, or is there a way to indicate this?</p>
  
  <p>Ultimately I want to achieve something like this:</p>
  
  <pre><code>Person *john = [[Person alloc] init];
  
  //here code that assigns john three traits: TraitsCharacterHonest,      
  //TraitsCharacterOptimistic and TraitsPhysicalBeautiful.
  </code></pre>
  
  <p>If I understand it correctly, the value of </p>
  
  <p>john.traits should be 100011., reading from right and each place representing that particular enum value / trait..and 0 meaning not having it and 1 meaning having it.</p>
  
  <p>Can you please advice on syntax and explain a particular aspect if needed?</p>