hex.c (308B)
1 2 int hex_bytes(unsigned char *bytes, int n_bytes, char *buf, int buf_size) 3 { 4 static const char *hex = "0123456789abcdef"; 5 int b; 6 7 if (n_bytes * 2 < buf_size) 8 return 0; 9 10 for (int i = 0; i < buf_size; i++) { 11 b = bytes[i/2]; 12 b = i % 2 ? b & 0x0F : (b & 0xF0) >> 4; 13 buf[i] = hex[b]; 14 } 15 16 return 1; 17 }