Skip to content

Instantly share code, notes, and snippets.

@alepez
Created June 14, 2019 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alepez/44c2119f1ce871d328515c683620bc16 to your computer and use it in GitHub Desktop.
Save alepez/44c2119f1ce871d328515c683620bc16 to your computer and use it in GitHub Desktop.
print byte array as human readble hex numbers
inline void printHex(const uint8_t* s, unsigned size)
{
for (unsigned i = 0; i != size; ++i)
{
if (s[i] > ' ' && s[i] <= '~')
{
printf("'%c' %02x ", s[i], (int)s[i]);
}
else
{
printf(" %02x ", (int)s[i]);
}
}
printf("\n");
}
inline void printHex(const std::stringstream& ss)
{
auto s = ss.str();
printHex((const uint8_t*)s.c_str(), s.size());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment