44 if(c >=
'0' && c <=
'9') {
47 if(c >=
'a' && c <=
'f') {
50 if(c >=
'A' && c <=
'F') {
57 hexconv_hexlify(
const uint8_t *data,
int data_len,
char *text,
int text_size)
59 static const char *HEX =
"01234567890abcdef";
62 for(i = 0, p = 0; p + 1 < text_size && i < data_len; i++) {
63 text[p++] = HEX[(data[i] >> 4) & 0xf];
64 text[p++] = HEX[data[i] & 0xf];
70 hexconv_unhexlify(
const char *text,
int text_len, uint8_t *buf,
int buf_size)
74 if((text_len & 1) != 0) {
79 for(i = 0, p = 0; p < buf_size && i + 1 < text_len; i += 2, p++) {
80 c1 = fromhex(text[i]);
81 c2 = fromhex(text[i + 1]);
82 if(c1 < 0 || c2 < 0) {
85 buf[p] = ((c1 << 4) & 0xf0) + (c2 & 0xf);
91 hexconv_print(
const uint8_t *data,
int data_len)
94 for(i = 0; i < data_len; i++) {
95 printf(
"%02x", data[i]);
A small util to convert between bytes and hex string
Default definitions of C compiler quirk work-arounds.