Chinaunix

标题: busybox中将二进制数据转为十六进制的字符串怎么理解? [打印本页]

作者: qianguozheng    时间: 2017-08-16 11:28
标题: busybox中将二进制数据转为十六进制的字符串怎么理解?
本帖最后由 qianguozheng 于 2017-08-16 11:29 编辑
  1. const char bb_hexdigits_upcase[] ALIGN1 = "0123456789ABCDEF";
复制代码
希望有大神能够解读下这个函数,水平有限无法完整的理解。

  1. /* Emit a string of hex representation of bytes */
  2. char* FAST_FUNC bin2hex(char *p, const char *cp, int count)
  3. {
  4.         while (count) {
  5.                 unsigned char c = *cp++;
  6.                 /* put lowercase hex digits */
  7.                 *p++ = 0x20 | bb_hexdigits_upcase[c >> 4];
  8.                 *p++ = 0x20 | bb_hexdigits_upcase[c & 0xf];
  9.                 count--;
  10.         }
  11.         return p;
  12. }
复制代码








作者: 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