Skip to content

Instantly share code, notes, and snippets.

@mykola2312
Last active March 31, 2022 14:59
Show Gist options
  • Save mykola2312/d40d9156a8683b9d578c46ed4c6703ba to your computer and use it in GitHub Desktop.
Save mykola2312/d40d9156a8683b9d578c46ed4c6703ba to your computer and use it in GitHub Desktop.
text hex to binary data
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