Skip to content

Instantly share code, notes, and snippets.

@rikioy
Last active June 1, 2016 02:56
Show Gist options
  • Select an option

  • Save rikioy/070d94207e90ce77c1e6455d27609d41 to your computer and use it in GitHub Desktop.

Select an option

Save rikioy/070d94207e90ce77c1e6455d27609d41 to your computer and use it in GitHub Desktop.
bin2hex
std::string bin2hex(const std::string& input)
{
std::string res;
const char hex[] = "0123456789ABCDEF";
for(unsigned int i = 0; i < input.size(); i++)
{
char sc = input[i];
unsigned char c = static_cast<unsigned char>(sc);
res += hex[c >> 4];
res += hex[c & 0xf];
}
return res;
}
@y109
Copy link

y109 commented May 11, 2016

NB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment