Skip to content

Instantly share code, notes, and snippets.

@alepez
Created January 8, 2019 07:43
Show Gist options
  • Save alepez/04c6ae3ab44dfa9c62a0df905deb733e to your computer and use it in GitHub Desktop.
Save alepez/04c6ae3ab44dfa9c62a0df905deb733e to your computer and use it in GitHub Desktop.
encodeBase16
static void encodeBase16(char* const dst, const void* const src, const unsigned size) {
static const uint8_t table[] = "0123456789ABCDEF";
char* d = dst;
const uint8_t* s = static_cast<const uint8_t*>(src);
const uint8_t* const sEnd = s + size;
while (s < sEnd) {
const uint8_t c = *s;
*d = table[c >> 4];
++d;
*d = table[c & 0xf];
++s;
++d;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment