I have troubles with printing a big 16 digits hex number in c
unsigned long long j = 0x89ABCDEF12893456;
printf("0x%lx\n", j); //prints: 0x12893456
printf("%#lx", j); //prints: 0x12893456
is there a way to print the whole number?
I have troubles with printing a big 16 digits hex number in c
unsigned long long j = 0x89ABCDEF12893456;
printf("0x%lx\n", j); //prints: 0x12893456
printf("%#lx", j); //prints: 0x12893456
is there a way to print the whole number?
As per the C standard, C11 7.21.6 Formatted input/output functions /7
which discusses length modifiers:
ll
(ell-ell): Specifies that a followingd
,i
,o
,u
,x
, orX
conversion specifier applies to along long int
orunsigned long long int
argument; or that a followingn
conversion specifier applies to a pointer to along long int
argument.
A single l
specifies a long
or unsigned long
. Hence %llx
or %#llx
is the format specifier you want, possibly with an output length and zero padding as well, if you want the numbers to line up (such as "0x%016llx"
).
That should do it.
#include <stdio.h>
int main () {
unsigned long long j = 0x89ABCDEF12893456;
printf("%#llx", j);
return 0;
}