Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable printf format specifier for 64 bit hexadecimal? [duplicate]

Tags:

c

printf

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.

like image 407
thmiller Avatar asked Sep 23 '15 17:09

thmiller


1 Answers

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

like image 111
Brett Hale Avatar answered Oct 21 '22 04:10

Brett Hale