base16_to.c 391 B

123456789101112131415161718192021
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include "types.h"
  4. #include "base16.h"
  5. static const char base16t[16] = {
  6. '0', '1', '2', '3',
  7. '4', '5', '6', '7',
  8. '8', '9', 'A', 'B',
  9. 'C', 'D', 'E', 'F',
  10. };
  11. char *base16_to(char *dst, const u8 *src, size_t slen)
  12. {
  13. for (size_t i = 0; i < slen; ++i) {
  14. *dst++ = base16t[src[i] >> 4];
  15. *dst++ = base16t[src[i] & 15];
  16. }
  17. *dst = 0;
  18. return dst;
  19. }