如何在char数组中输入8字节的hex数?

我想生成以07060504003020100开头的hex数字序列。 下一个数字将按顺序为0f0e0d0c0b0a0908等。

当我使用unsigned long long int并输出前4位数据时,意味着0被截断。 它打印706050403020100

所以我想把数字放入一个char数组缓冲区(或其他一些缓冲区)然后打印输出,以便以后如果我想比较我可以进行字符/字节比较。

有人可以帮帮我吗? char[8]="0x0706050403020100"看起来不正确。

你用什么来打印你的价值? 将8个0填充字节打印到stdout的语法类似于

 printf("%016X", value); 

它像这样崩溃:

 %x = lowercase hex %X = uppercase hex %16X = always 16 characters (adds spaces) %016X = zero-pad so that the result is always 16 characters 

例如,您可以在基数10中执行相同的操作:

 printf("%05d", 3); // output: 00003 

你也可以玩小数:

 printf("%.05f", 0.5); // output: 0.50000 

http://www.cplusplus.com/reference/clibrary/cstdio/printf/