I wonder how I use printf to print an unsigned 64 bit integer in hex? I want to print all positions, even if they are zero like this:
0000000000000000
or:
00FFFFFFFFFFFFFF
or:
000C5AB7643DAA4F
I wonder how I use printf to print an unsigned 64 bit integer in hex? I want to print all positions, even if they are zero like this:
0000000000000000
or:
00FFFFFFFFFFFFFF
or:
000C5AB7643DAA4F
You cantīt teach an old dog new tricks.
printf() format modifiers maybe. This is the code for a regular int:
>printf ("%010d\n", 9);
The first 0 of 010 tells the compiler to print leading 0's.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
This does not work. When building I get a warning:Originally posted by penney
printf("%016X\n",your_num);
unsigned int format, difference type arg (arg 2)
And the resulting output is:
00000000FFFFFFFF
This is my code:
UInt64 your_num = 0xffffffffffffffff;
printf("%016X\n", your_num);
What is wrong?
You cantīt teach an old dog new tricks.
IT WORKS!!!Originally posted by Monster
Try:Code:printf("%016llX\n", your_num);
Thanks a lot my friend. No build error and the output is exactly as it should. I own you one :-)
What have this learned me? Well, even Monster's can be nice, heh...
You cantīt teach an old dog new tricks.
It's from cookie monster.... I love cookiesOriginally posted by electrolove
IT WORKS!!!
Thanks a lot my friend. No build error and the output is exactly as it should. I own you one :-)
What have this learned me? Well, even Monster's can be nice, heh...
b.t.w. I'm not sure if this is ANSI C
As far as I understand the ANSI C Standard, I would say "%016llX" is ANSI C conform.Originally posted by Monster
b.t.w. I'm not sure if this is ANSI C
0 For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros
(following any indication of sign or base) are used to pad to the field width rather
than performing space padding, except when converting an infinity or NaN. If the
0 and - flags both appear, the 0 flag is ignored. For d, i, o, u, x, and X
conversions, if a precision is specified, the 0 flag is ignored. For other
conversions, the behavior is undefined.
...
ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a
long long int or unsigned long long int argument; or that a
following n conversion specifier applies to a pointer to a long long int
argument.
...
o,u,x,X The unsigned int argument is converted to unsigned octal (o), unsigned
decimal (u), or unsigned hexadecimal notation (x or X) in the style dddd; the
letters abcdef are used for x conversion and the letters ABCDEF for X
conversion. The precision specifies the minimum number of digits to appear;
if the value being converted can be represented in fewer digits, it is expanded
with leading zeros. The default precision is 1. The result of converting a
zero value with a precision of zero is no characters.