Chinaunix
标题:
busybox中将二进制数据转为十六进制的字符串怎么理解?
[打印本页]
作者:
qianguozheng
时间:
2017-08-16 11:28
标题:
busybox中将二进制数据转为十六进制的字符串怎么理解?
本帖最后由 qianguozheng 于 2017-08-16 11:29 编辑
const char bb_hexdigits_upcase[] ALIGN1 = "0123456789ABCDEF";
复制代码
希望有大神能够解读下这个函数,水平有限无法完整的理解。
/* Emit a string of hex representation of bytes */
char* FAST_FUNC bin2hex(char *p, const char *cp, int count)
{
while (count) {
unsigned char c = *cp++;
/* put lowercase hex digits */
*p++ = 0x20 | bb_hexdigits_upcase[c >> 4];
*p++ = 0x20 | bb_hexdigits_upcase[c & 0xf];
count--;
}
return p;
}
复制代码
作者:
qianguozheng
时间:
2017-08-17 10:31
没有大神给看看阿
作者:
amarant
时间:
2017-08-17 16:28
逻辑不难啊?要觉得难理解用 gdb 单步跟一下吧。
作者:
qianguozheng
时间:
2017-08-18 10:53
回复
3#
amarant
授人以鱼不知授之以渔。 赞
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2