Last active
May 22, 2019 06:52
-
-
Save Zibri/992b38baa520eb478ef7fa15fd950a7a 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
/* | |
Best hex2bin function I came up with. | |
By Zibri | |
Valid strings examples: | |
"1 d0 600d c0FFeE" | |
"01d0600dc0ffee" | |
Spaces are ignored. | |
Parsing stops at the first non hex character. | |
Mixed case accepted. | |
*/ | |
int hex2bin_by_zibri(char *source_str, char *dest_buffer) | |
{ | |
char *line = source_str; | |
char *data = line; | |
int offset; | |
int read_byte; | |
int data_len = 0; | |
while (sscanf(data, " %02x%n", &read_byte, &offset) == 1) { | |
dest_buffer[data_len++] = read_byte; | |
data += offset; | |
} | |
return data_len; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment