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
.
%ul will just print unsigned (with %u), and then the letter "l" verbatim. Just as "%uw" will print unsigned, followed by letter "w".
To print integer number in Hexadecimal format, "%x" or "%X" is used as format specifier in printf() statement. "%x" prints the value in Hexadecimal format with alphabets in lowercase (a-f). "%X" prints the value in Hexadecimal format with alphabets in uppercase (A-F).
long hexLong = 0XABL; For Hexadecimal, the 0x or 0X is to be placed in the beginning of a number. Note − Digits 10 to 15 are represented by a to f (A to F) in Hexadecimal.
An unsigned Integer means the variable can hold only a positive value. This format specifier is used within the printf() function for printing the unsigned integer variables. printf(“%u”, value);
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:
printf
documentation on cppeference.comtry %llu
- this will be long long unsigned in decimal form
%llx
prints long long unsigned in hex
printf("Hex add is: %llu", hexAdd);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With