unsigned long long type printing in hexadecimal format

Paul the Pirate picture Paul the Pirate · Oct 10, 2013 · Viewed 92.9k times · Source

I am trying to print out an unsigned long long like this:

  printf("Hex add is: 0x%ux ", hexAdd);

but I am getting type conversion errors since I have an unsigned long long.

Answer

gavinb picture gavinb · Oct 10, 2013

You can use the same ll size modifier for %x, thus:

#include <stdio.h>

int main() {
    unsigned long long x = 123456789012345ULL;
    printf("%llx\n", x);
    return 0;
}

The full range of conversion and formatting specifiers is in a great table here: