title: C and signed byte representation in memory
body: <p>There's something I dont get:</p>
  
  <p>A <code>signed char</code> in C is represented on 8 bits:<code>00000000</code></p>
  
  <ul>
  <li>0 is <code>0000 0000</code> => 0</li>
  <li>1 is <code>0000 0001</code> => 1</li>
  <li>...</li>
  <li>127 is <code>0111 1111</code> => 127</li>
  </ul>
  
  <p>So I thought the 8th bits is the sign bit.
  So I thought:</p>
  
  <ul>
  <li>128 is <code>1000 0000</code> => 0</li>
  <li>129 is <code>1000 0001</code> => -1</li>
  </ul>
  
  <p>But no!</p>
  
  <p>Try this:</p>
  
  <pre><code>int main(int argc, const char *argv[])
  {
      int i;
      for (i = 0; i &lt; 256; i++) {
          printf("%3d = %d\n", i, (signed char)i);
      }
      return 0;
  }
  </code></pre>
  
  <p>And you get: <code>gcc -o tt tt.c ; ./tt | more</code></p>
  
  <ul>
  <li>...</li>
  <li><code>126 = 126</code></li>
  <li><code>127 = 127</code></li>
  <li><code>128 = -128</code></li>
  <li><code>129 = -127</code></li>
  <li><code>130 = -126</code></li>
  <li><code>254 = -2</code></li>
  <li><code>255 = -1</code></li>
  </ul>
  
  <p>How comes?</p>