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.

Revisions

  1. denisvm created this gist Mar 5, 2014.
    13 changes: 13 additions & 0 deletions hex2bin.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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);
    }
    }