Migrating a printf format specifier for 64-bit hex?

What printf format specifier can be used to print a 64-bit unsigned integer in 32/64 bit hex notation and Windows / POSIX? The closest I've seen is %llX , but I'm not sure if it's portable enough. Answers that are ignored by older compilers (e.g. Visual Studio 2010) are acceptable.

+5
source share
2 answers

The PRIx64 macro in <inttypes.h> is what you are looking for.

This is a text token, so you can use it like: fprintf(stdout, "answer = %"PRIx64"\n", val);

Since you specify %llX , you probably want to have uppercase letters; use: PRIx64

+6
source

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

+1
source

Source: https://habr.com/ru/post/1232122/


All Articles