1 2 3 4 5 6 7 8 9 10 11 12 13 14
| int bin2hex(const unsigned char *i, size_t l, unsigned char *o, size_t s) { static char hex2char[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; size_t pos = 0; size_t walk = 0; for(pos = 0; pos < l && walk < s-1; pos++) { unsigned char H = i[pos] >> 4; unsigned char L = i[pos] & 0x0F; o[walk++] = hex2char[H]; o[walk++] = hex2char[L]; } return walk; }
|