Skip to content

Instantly share code, notes, and snippets.

@rdhiggins
Created November 18, 2022 16:00
Show Gist options
  • Save rdhiggins/eb564899fe31a808431e5376521282d1 to your computer and use it in GitHub Desktop.
Save rdhiggins/eb564899fe31a808431e5376521282d1 to your computer and use it in GitHub Desktop.
Takes a collection of binary data and creates a hex string from it.
template <typename STD_COLLECTION>
std::string as_hex_string(STD_COLLECTION&& collection) {
std::stringstream ss;
for (unsigned char c: std::forward<STD_COLLECTION>(collection))
ss << std::setfill('0') << std::setw(2) << std::hex << static_cast<short>(c) << " ";
return ss.str();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment