title: Write Hex in C (byte)
body: <p>I have to write a byte in hex to a file but I have a problem. For example.</p>
  
  <p>If I have:</p>
  
  <pre><code>unsigned char a = 0x0;
  </code></pre>
  
  <p>and I write to a file using fwrite:</p>
  
  <pre><code>FILE *fp = fopen("file.txt",wb);
  fwrite(&amp;a,sizeof(unsigned char),1,fp);
  fclose(fp);
  </code></pre>
  
  <p>When I open file I always see 20h, why not 00h?</p>
  
  <p>So, I try to use:</p>
  
  <pre><code>fprintf(fp,"%x",a);
  </code></pre>
  
  <p>In this case I see 0h, but I need a full byte, not a nibble.
  What should I do?</p>