char toHexChar(unsigned char byte)
{
if(byte < 10)
{
return (char)('0' + byte);
}
else
{
return (char)('a' + byte - 10);
}
}
string toHex(unsigned char byte)
{
string ans;
if(byte < 16)
{
ans += "0";
ans += toHexChar(byte);
}
else
{
unsigned char lower = byte % 16;
byte /= 16;
ans += toHexChar(byte);
ans += toHexChar(lower);
}
return ans;
}
// test all byte values
for(int i=0;i<256;++i)
{
if(i % 16 == 0)
{
cout << endl;
}
cout << toHex(i) << ' ';
}