Created
April 20, 2016 11:05
-
-
Save clzola/b7f1d9dfacab7a253afce7ca3d5aeb23 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
unsigned char* hex2bin(const char* hexstr, size_t* size) | |
{ | |
size_t hexstrLen = strlen(hexstr); | |
size_t bytesLen = hexstrLen / 2; | |
unsigned char* bytes = (unsigned char*) malloc(bytesLen); | |
int count = 0; | |
const char* pos = hexstr; | |
for(count = 0; count < bytesLen; count++) { | |
sscanf(pos, "%2hhx", &bytes[count]); | |
pos += 2; | |
} | |
if( size != NULL ) | |
*size = bytesLen; | |
return bytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment