Skip to content

Instantly share code, notes, and snippets.

@lemonlatte
Last active November 5, 2019 12:27
Show Gist options
  • Save lemonlatte/684c6747a2f3b704c92da095eac550de to your computer and use it in GitHub Desktop.
Save lemonlatte/684c6747a2f3b704c92da095eac550de to your computer and use it in GitHub Desktop.
encode hex
unsigned int encode_hex(char *out, size_t out_sz, uint8_t *in, size_t in_sz) {
if (in_sz*2 + 1>out_sz) {
return 0;
}
uint8_t i;
for (i = 0; i < in_sz; i++) {
snprintf(out+i*2, 3, "%02x", in[i]);
}
return in_sz*2+1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment