I am printing converted hexadecimal values like the following:
std::cout << std::hex << integers[i] << " "; //i is a loop counter
But it prints out single digits for few values, like FF D2 78 9 A9 87 f ff
. I want those single values to have a 0: FF D2 78 09 A9 87 0f ff
.
I tried
if(integers[i] == 1 || ... || integers[i] = (int)'f')
{
std::cout << "0" << std::hex << integers[i] << " ";
}
But when 1 ... f is an hexadecimal value it, it does not print properly. How can I convert the value to hex first and check if its one digit or two digits and add 0 padding if it is a single digit?