Created
April 28, 2009 13:40
-
-
Save kulp/103156 to your computer and use it in GitHub Desktop.
Convert N-byte string into hex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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