先取数据地址,转换成单字节长度的类型(unsigned char)的指针,然后按照十六进制逐字节打印即可,格式为“%.2x”。
sizeof()函数获取数据的字节数。
1 /* $begin show-bytes */
2 #include <stdio.h>
3 /* $end show-bytes */
4 #include <stdlib.h>
5 #include <string.h>
6 /* $begin show-bytes */
7
8 typedef unsigned char *byte_pointer;
9
10 void show_bytes(byte_pointer start, int len) {
11 int i;
12 for (i = 0; i < len; i++)
13 printf(" %.2x", start[i