开发者

How to input 8 byte hexadecimal number into char array?

I want to generate sequence of hexadecimal numbers starting with 07060504003020100. Next number would be 0f0e0d0c0b0a0908 etc in that order.

When I use unsigned long long int and output the data the first开发者_开发问答 4 bits, meaning that 0 is truncated. and it prints 706050403020100.

So I was thinking of putting the number into a char array buffer(or some other buffer) and then print the output so that later if I want to compare I can do character/byte wise compare.

Can anybody help me out? char[8]="0x0706050403020100" doesn't look right.


What are you using to print out your value? The syntax for printing 8 0-padded bytes to stdout would be something like

printf("%016X", value);

It breaks down like this:

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

For example, you could do the same thing in base 10:

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

You can also play with decimals:

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜