Skip to content

Instantly share code, notes, and snippets.

@kulp
Created April 28, 2009 13:40
Show Gist options
  • Save kulp/103156 to your computer and use it in GitHub Desktop.
Save kulp/103156 to your computer and use it in GitHub Desktop.
Convert N-byte string into hex
/// Convert N-byte string into hex
char* tohex(int len, const char input[len])
{
char *buf = malloc(2 * len + 1);
int pos = 0;
for (const char *i = input; i < input + len; i++)
pos += sprintf(&buf[pos], "%02x", *i);
return buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment