| 203 | } |
| 204 | |
| 205 | char *bintohex(uint8_t *data, size_t len) |
| 206 | { |
| 207 | static const char __nonstring translate[16] = "0123456789abcdef"; |
| 208 | |
| 209 | char *result = malloc(len * 2 + 1); |
| 210 | if (result == NULL) |
| 211 | return NULL; |
| 212 | |
| 213 | result[len*2] = '\0'; |
| 214 | unsigned int i; |
| 215 | for (i = 0; i < len; i++) { |
| 216 | result[i*2] = translate[(data[i] >> 4) & 0xf]; |
| 217 | result[i*2+1] = translate[data[i] & 0xf]; |
| 218 | } |
| 219 | return result; |
| 220 | } |
no test coverage detected