title: How to print unsigned char as 2-digit hex value in C?
body: <p>I am trying to printout an unsigned char value as a 2-Digit hex value, but always getting the result as 4-Digit hex values, not sure what's wrong with my code.</p>
  
  <pre><code>// unsigned char declaration
  unsigned char status = 0x00;
  // printing out the value 
  printf("status = (0x%02X)\n\r", (status |= 0xC0));
  </code></pre>
  
  <p>I am expecting a 2 digit hex result as <code>0xC0</code>, but I always get <code>0xC0FF</code>.</p>
  
  <p>As well, when I tried to print the same variable (status) as an unsigned char with the <code>%bu</code> format identifier I got the output as <code>255</code>.</p>
  
  <p>How do you get just the two hex characters as output?</p>