Skip to content

Instantly share code, notes, and snippets.

@drewr
Created November 18, 2011 15:30
Show Gist options
  • Save drewr/1376760 to your computer and use it in GitHub Desktop.
Save drewr/1376760 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
void hex2char(char *a, unsigned char *buf)
{
int ch;
char tmp[2];
int i, j;
for (i=0,j=0; i<strlen(a); i=i+2,j++) {
tmp[0] = a[i];
tmp[1] = a[i+1];
sscanf(tmp, "%x", &ch);
buf[j] = ch;
/* printf("%i %i %i \"%s\"\n", j, i, ch, buf); */
}
}
int main(int argc, char **argv)
{
static unsigned char b[16];
hex2char("3D75AF12F7EAB46764B725CE95DBEBA9", b);
printf("strlen(b) -> %zu\n", strlen((char*)b));
/*
int k;
for (k=0; k<strlen(buf); k++) { }
*/
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment