 <p>Where the output should be <code>0c</code>, your code only outputs the <code>c</code> part. This is because <code>printf</code> by default prints the result with the minimum number of characters possible. In this case, you should tell <code>printf</code> that the proper result always contains two hexadecimal digits by giving it a width, and by specifying that a zero should be placed in the most-significant nibble if the input is less than <code>0x10</code>:</p> <pre><code>printf("%02x", output[i]); </code></pre>