Skip to content

Instantly share code, notes, and snippets.

@denisvm
Created March 5, 2014 21:29
Show Gist options
  • Select an option

  • Save denisvm/9377022 to your computer and use it in GitHub Desktop.

Select an option

Save denisvm/9377022 to your computer and use it in GitHub Desktop.
static void hex2bin(unsigned char *to, const char *p, size_t len) {
register char c1, c2;
for (; *p; to++) {
c1 = *p++; c2 = *p++;
if (!c1 || !isxdigit(c1))
return;
else if (!c2 || !isxdigit(c2))
*to = (unsigned char) digittoint(c1);
else
*to = (unsigned char) (digittoint(c1) << 4) | digittoint(c2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment