背景:
unsigned char port[5];
以02x的格式打印出来是 00 00 02 00 00
1.如何转成16进制形式的字符串,使得char *strport16 = "0000020000";
2.如何转成10进制形式的字符串,使得char *strport10 = "131072";
C code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
unsigned char port[5] = {0x00, 0x00, 0x02, 0x00, 0x00};
char buf[20] = {0};
// format port[] to hex result
sprintf(buf, "%02x%02x%02x%02x%02x", port[0], port[1], port[2], port[3], port[......
阅读全文