52 for (i = 0; i < bLen; i++) {
54 if (str[i * 2] >=
'0' && str[i * 2] <=
'9') {
55 *out = (str[i * 2] -
'0') << 4;
57 if (str[i * 2] >=
'a' && str[i * 2] <=
'f') {
58 *out = (10 + str[i * 2] -
'a') << 4;
60 if (str[i * 2] >=
'A' && str[i * 2] <=
'F') {
61 *out = (10 + str[i * 2] -
'A') << 4;
63 if (str[i * 2 + 1] >=
'0' && str[i * 2 + 1] <=
'9') {
64 *out |= (str[i * 2 + 1] -
'0');
66 if (str[i * 2 + 1] >=
'a' && str[i * 2 + 1] <=
'f') {
67 *out |= (10 + str[i * 2 + 1] -
'a');
69 if (str[i * 2 + 1] >=
'A' && str[i * 2 + 1] <=
'F') {
70 *out |= (10 + str[i * 2 + 1] -
'A');
85 for (i = 0; i <
strlens(str) / 2; i++) {
87 if (str[i * 2] >=
'0' && str[i * 2] <=
'9') {
88 c += (str[i * 2] -
'0') << 4;
90 if (str[i * 2] >=
'a' && str[i * 2] <=
'f') {
91 c += (10 + str[i * 2] -
'a') << 4;
93 if (str[i * 2] >=
'A' && str[i * 2] <=
'F') {
94 c += (10 + str[i * 2] -
'A') << 4;
96 if (str[i * 2 + 1] >=
'0' && str[i * 2 + 1] <=
'9') {
97 c += (str[i * 2 + 1] -
'0');
99 if (str[i * 2 + 1] >=
'a' && str[i * 2 + 1] <=
'f') {
100 c += (10 + str[i * 2 + 1] -
'a');
102 if (str[i * 2 + 1] >=
'A' && str[i * 2 + 1] <=
'F') {
103 c += (10 + str[i * 2 + 1] -
'A');
113 static char digits[] =
"0123456789abcdef";
115 for (i = 0; i < inlen; i++) {
116 hex_out[i * 2] = digits[(bin_in[i] >> 4) & 0xF];
117 hex_out[i * 2 + 1] = digits[bin_in[i] & 0xF];
119 hex_out[inlen * 2] =
'\0';
128 static char digits[] =
"0123456789abcdef";
131 for (i = 0; i < l; i++) {
143 strncpy(copy, h, len);
145 for (i = 0; i <
len; i += 2) {
146 h[i] = copy[len - i - 2];
147 h[i + 1] = copy[len - i - 1];
158 sprintf(v,
"%02" PRIx64, i);
160 }
else if (i <= 0xffff) {
161 sprintf(v,
"%04" PRIx64, i);
164 }
else if (i <= 0xffffffff) {
165 sprintf(v,
"%08" PRIx64, i);
169 sprintf(v,
"%016" PRIx64, i);
193 }
else if (!strncmp(vi,
"ff", 2)) {
195 }
else if (!strncmp(vi,
"fe", 2)) {
197 }
else if (!strncmp(vi,
"fd", 2)) {
205 }
else if (len > 2) {
206 strncpy(v, vi + 2, len);
211 *i = strtoull(v, NULL, 16);
uint8_t * utils_hex_to_uint8(const char *str)
void utils_hex_to_bin(const char *str, unsigned char *out, int inLen, int *outLen)
static uint8_t buffer_hex_to_uint8[TO_UINT8_HEX_BUF_LEN]
void utils_clear_buffers(void)
static char buffer_uint8_to_hex[TO_UINT8_HEX_BUF_LEN]
int utils_varint_to_uint64(const char *vi, uint64_t *i)
#define TO_UINT8_HEX_BUF_LEN
void utils_reverse_hex(char *h, int len)
char * utils_uint8_to_hex(const uint8_t *bin, size_t l)
void utils_bin_to_hex(unsigned char *bin_in, size_t inlen, char *hex_out)
void utils_uint64_to_varint(char *vi, int *l, uint64_t i)