Reputation: 152
I saw in some functions that in order to convert number to hexadecimal format, using this format: printf("%02hhx", some_char);
, but I don't understand why, and what is the meaning of this format ?
Upvotes: 1
Views: 3023
Reputation: 12404
Format string "%02hhx"
means:
0
: Results that would require less than specified field width shall be printed with leading 0
s.2
: use at least 2 characters to format the valuex
Print in hexadecimal format.hh
The provided parameter for x
is only a char
, not an int
For values 0..127
it doesn't matter if you add the hh
but values above could get sign extended and would be printed with lots of leading F
.The result will just be a hexadecimal value with 2 digits.
Upvotes: 4