title: I want to calculate the inverse mask for an unsigned char
body: <p>I would like to calculate an inverse mask for an unsigned char.meaning if the original mask 0xc0 the the inverse mask should be 0x3f.that is to say all the bits should be flipped or inverted.I have tried the below but doesn't seem to be working.</p>
  
  <pre><code>int flipBit(int x, unsigned char position)
  {
    int mask = 1 &lt;&lt; position;
    return x ^ mask;
  }
  
  int main(int argc , char* argv[])
  {
          uint8_t mask = 0x03;
          uint8_t inverse_mask = 0;
          uint8_t temp = 0;
          int loop = 0;
  
          for (loop = 0; loop &lt; 8 ; loop ++)
          {
                  temp = flipBit(mask,loop);
                  inverse_mask |= temp;
          }
          printf("mask 0x%x inv mask 0x%x \n",mask,inverse_mask);
          return 0;
  }
  </code></pre>
  
  <p>The results I get are 
  mask 0x3 inv mask 0xff</p>
  
  <p>I cannot seem to find the bug in my code.</p>