title: sscanf 1 byte hex data without overflow
body: <p>I need to scan a hex representation of 6 bytes data and store it in a 6 byte array.</p>
  
  <p>Please note I am in an embedded system so every byte count.</p>
  
  <p>Using sscanf this way :</p>
  
  <pre><code>uint8_t buf[6];
  char hex[13] = "123456789ABC";
  sscanf(hex, "%02X%02X%02X%02X%02X%02X", &amp;buf[0], &amp;buf[1], &amp;buf[2], &amp;buf[3], &amp;buf[4], &amp;buf[5]);
  </code></pre>
  
  <p>is overflowing because each %02X specifier load in a uint32_t.</p>
  
  <ul>
  <li>%02lX will load in a uint32_t</li>
  <li>%02hX will load in a uint16_t</li>
  </ul>
  
  <p>Is there a specifier that load in a uint8_t ? (I don't find it anywhere)</p>
  
  <p>Is there another way of doing this ?</p>
  
  <p>I tried to do :</p>
  
  <pre><code>sscanf(hex, "%08lX%04hX", &amp;buf[0], &amp;buf[4]);
  </code></pre>
  
  <p>this does not overflow, but as I am on little endian structure, the order is mixed up...</p>