title: Comparing chars with hex values
body: <p>For the last day I have had a nasty bug in my code which after some searching appears to be related to comparison between char values and hex. My compiler is gcc 4.4.1 running on Windows.
  I replicated the problem in the simple code below:</p>
  
  <pre><code>char c1 = 0xFF; char c2 = 0xFE;
  if(c1 == 0xFF &amp;&amp; c2 == 0xFE)
  {
      //do something
  }
  </code></pre>
  
  <p>Surprisingly the code above does not get in the loop. I have absolutely no idea why and would really appreciate some help on this. It is so absurd that the solution must be (as always) a huge mistake on my part that I totally overlooked.</p>
  
  <p>If I replace the above with unsigned chars it works, but only in some cases. I am struggling to find out what's going on. In addition if I cast the hex values to char in comparison it enters the loop  correctly like so:</p>
  
  <pre><code>if(c1 == (char)0xFF &amp;&amp; c2 == (char)0xFE)
  {
      //do something
  }
  </code></pre>
  
  <p>What does that mean? Why can it be happening? Isn't the raw hex value interpreted as a char by default?
  For the curious the point in my code where I first noticed it is comparison of first 2 bytes of a stream with the above hex value and their reverse to idenity the Byte Order Mark.</p>
  
  <p>Any help is appreciated</p>