title: printf char as hex in c
body: <p>I expect ouput something like <code>\9b\d9\c0...</code> from code below, but I'm getting <code>\ffffff9b\ffffffd9\ffffffc0\ffffff9d\53\ffffffa9\fffffff4\49\ffffffb0\ffff
  ffef\ffffffd9\ffffffaa\61\fffffff7\54\fffffffb</code>. I added explicit casting to char, but it has no effect. What's going on here?</p>
  
  <pre class="lang-c prettyprint-override"><code>typdef struct PT {
      // ... omitted
      char GUID[16];
  } PT;
  PT *pt;
  // ... omitted
  int i;
  for(i=0;i&lt;16;i++) {
      printf("\\%02x", (char) pt-&gt;GUID[i]);
  }
  </code></pre>
  
  <p><strong>Edit:</strong> only casting to <code>(unsigned char)</code> worked for me. Compiler spits warnings on me when using <code>%02hhx</code> (<code>gcc -Wall</code>). <code>(unsigned int)</code> had no effect.</p>