title: Bit shifting coding efficiency (i.e. neat tricks)
body: <p>I'm working on a Objective-C program where I'm getting bitfields over the network, and need to set boolean variables based on those bits.</p>
  
  <p>Currently I'm representing the bitfields as <code>int</code>'s, and then using bit shifting, similar to this (all the self properties are BOOL):</p>
  
  <pre><code>typedef enum {
      deleteFlagIndex = 0,
      uploadFlagIndex = 1,
      moveFlagIndex = 2,
      renameFlagIndex = 3
  } PrivilegeFlagIndex;
  
  int userFlag = 5; //for example
  
  // this would be YES
  self.delete = ((userFlag &amp; (1 &lt;&lt; deleteFlagIndex)) == (1 &lt;&lt; deleteFlagIndex));
  // this would be NO
  self.upload = ((userFlag &amp; (1 &lt;&lt; uploadFlagIndex)) == (1 &lt;&lt; uploadFlagIndex));
  </code></pre>
  
  <p>And this works (to the best of my knowledge) but I'm wondering - is there a more <strike>efficient</strike> concise way to code all the bit twiddling using a fancy trick/hack? I ask because I'll be doing this for a <em>lot</em> of flags (more than 30).</p>
  
  <p>I did realize I could use this method this as well:</p>
  
  <pre><code>self.move = ((userFlag &amp; (1 &lt;&lt; moveFlagIndex)) &gt; 0)
  </code></pre>
  
  <p>...which does reduce the amount of typing, but I don't know if there's a good reason to not do it that way.</p>
  
  <p>Edit: Revised to say concise rather than efficient - I wasn't worried about execution performance, but rather tips and best practices for doing this in a smart way.</p>