What printf format specifier can I use to print a 64 bit unsigned integer in hexadecimal notation across 32/64 bit and Windows/POSIX? The closest I've seen is %llX
but I'm not sure that is portable enough. Answers that ignore older compilers (e.g. Visual Studio 2010) are acceptable.
Asked
Active
Viewed 7,120 times
9

thmiller
- 131
- 1
- 7
2 Answers
10
The PRIx64
macro in <inttypes.h>
is what you're looking for.
It's a string token, so you can use it as:
fprintf(stdout, "answer = %"PRIx64"\n", val);
Since you specify %llX
, you probably want uppercase; use: PRIX64

Brett Hale
- 21,653
- 2
- 61
- 90
-
That was it. The inttypes reference I was looking at only had PRIx macros up to 32 bits for some reason. – thmiller Sep 23 '15 at 18:20
-
1`printf("answer = %#018"PRIx64"\n", val)` to print leading zeros – Daniel May 12 '19 at 14:24
1
You can use macros PRIx64
or PRIX64 (for unsigned uppercase hexadecimal integer )
defined in header <inttypes.h>
.

ameyCU
- 16,489
- 2
- 26
- 41