title: C Manipulate Bits Within a Bit String
body: <p>I am currently working on a problem where I am trying to manipulate bits within a bit string.</p>
  
  <p>I am trying to take a signal mask given as:</p>
  
  <p><code>00101001</code></p>
  
  <p>and check it against a signal mask given as an integer using the AND and OR operators.</p>
  
  <p>I have some code currently that takes an unsigned character and prints out its binary representation, however I'm not sure how to continue.</p>
  
  <pre><code>main() {
      int signal = 2;
      unsigned char a = 41;
  
      int i;
      for (i = 0; i &lt; 8; i++) {
          printf("%d \n", !!((a &lt;&lt; i) &amp; 0x80));
      }
      printf("\n");
  
      return 0;
  }
  </code></pre>
  
  <ul>
  <li><em>The purpose of the program is supposed to take the signal number given, set all bits equal to 0 except the number bit that is the signal number and use an AND operator to find out if the signal is set or not based on whether the value is 0 or 1.</em></li>
  </ul>
  
  <p><strong>Note:</strong> Only one given signal number will be checked at run time.</p>
  
  <p>Can anybody help me out with this problem?</p>