printf 64bit value

Hey
I wanna print a 64 bit value but it doesn’t work.
I use de Digi Connect ME 9210 Embedded Linux and de DIGI ESP 5.7 Software.
The initialisation of my Value look the following way.

uint64_t test = 0x1234aaaa5678ffff.
No I wanna print this value.

printf("test: %llx
", test)

The Output from the Programm is this
test: 5678ffff0001387c

I don’t unterstand were the mistake is and why the program doesn’t print the value correct.

Please can anybody help

1 Like

On the Digi support page: http://www.digi.com/support/productdetail?pid=3510&type=documentation you can find the NS9210 CPU/Processor manual: http://ftp1.digi.com/support/documentation/90000846_K.pdf page 56:
> ARM926EJ-S processor supports the 32-
bit ARM and 16-bit Thumb instructions

So the hardware will only support 32bit data. Any 64bit data structures will need to be implemented in software e.g. by the compiler or math library. Also in C language the size of data types is depending on the machine type. So you should always run some test program first:

printf(" sizeof(int): %d
“, sizeof(int));
printf(” sizeof(long): %d
", sizeof(long));
printf("sizeof(long long): %d
“, sizeof(long long));
printf(” sizeof(float): %d
“, sizeof(float));
printf(” sizeof(double): %d
", sizeof(double));

On the ME 9210 this will show:
sizeof(int): 4
sizeof(long): 4
sizeof(long long): 8
sizeof(float): 4
sizeof(double): 8

so 64 bit is possible with (long long) or (unsigned long long). Maybe your definition of uint64_t does not match? What is sizeof(uint64_t)?

Other issue could be that C library used does not support printf(“%llx”, …) format string. Or its not possible to pass a 64bit variable to printf() as argument.

The following does work for me:
unsigned long long ull = 0;
ull–; /* count down to 0xff…ff */
printf("%llx
", (unsigned long long)ull );

prints: ffffffffffffffff = 64bit

So the problem is the automatic type conversion when passing the argument to printf() without explicit type conversion?

The problem can also be your variable initialization:

uint64_t test = 0x1234aaaa5678ffff

because the right side is auto converted into (int), so you should use:
uint64_t test = (unsigned long long)0x1234aaaa5678ffff;
or
uint64_t test = 0x1234aaaa5678ffffUL;

1 Like

Thank You for taking the time for this detailed answer, it helped me as well.