Last active
March 31, 2022 14:59
-
-
Save mykola2312/d40d9156a8683b9d578c46ed4c6703ba to your computer and use it in GitHub Desktop.
text hex to binary data
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
int htoi(char h) | |
{ | |
return h < 0x3A ? h - 0x30 : h - 0x57; | |
} | |
void strhex(const char* str, uint8_t* out) | |
{ | |
for (unsigned i = 0; i < strlen(str) >> 1; i++) | |
out[i] = htoi(str[i<<1]) << 4 | htoi(str[i<<1|1]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment