9

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.

thmiller
  • 131
  • 1
  • 7

2 Answers2

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
1

You can use macros PRIx64 or PRIX64 (for unsigned uppercase hexadecimal integer ) defined in header <inttypes.h>.

ameyCU
  • 16,489
  • 2
  • 26
  • 41