Created
November 18, 2011 15:30
-
-
Save drewr/1376760 to your computer and use it in GitHub Desktop.
This file contains 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
#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