I tried this with sprintf:
On output it only adds the leading zeros if the resulting hex number has a letter in it (A-F) if it doesn't (e.g. the number '8' or '112' etc.) then it doesn't add the leading zeros.
I attached the patch to check it out.