Skip to content

Instantly share code, notes, and snippets.

@zz-jason
Created March 28, 2017 06:12
Show Gist options
  • Save zz-jason/42513a6a1b2f636b42777f02b1b535c1 to your computer and use it in GitHub Desktop.
Save zz-jason/42513a6a1b2f636b42777f02b1b535c1 to your computer and use it in GitHub Desktop.
convert a char to its hex representation
std::string char_to_hex(unsigned char input)
{
static const char* const dict = "0123456789ABCDEF";
std::string result("0x");
result.push_back(dict[input >> 4]);
result.push_back(dict[input & 0x0F]);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment