Display a unint64_t in the Arduino IDE monitor

Hi all,

I would like to know how do you display a uint64_t on the monitor display. In fact, it is not possible to display it directly using Serial.print(uint64_t name). I tried to convert it in two uint32_t but I couldn't success it ...

Thanks for your help, cesc39

In what representation would you like to display it? Decimal? Hex?

Serial.print(uint64_t name) is invalid syntax. You want either Serial.print(name) or Serial.print((uint64_t) name).

Or try sprintf("%llu", name)

KeithRB: Serial.print(uint64_t name) is invalid syntax. You want either Serial.print(name) or Serial.print((uint64_t) name).

it is not implemented for the data type, is the point

Problem is, Serial.print() only goes up to uint32_t. So you'll need to split it.

For example for hex

 Serial.print((uint32_t)(name>> 32), HEX);
  Serial.println((uint32_t)name, HEX);

The avr sprintf() will not work either:

“But the ll length modifier will to abort the output, as this realization does not operate long long arguments.”

You can also modify K&R’s itoa():

/* itoa:  convert n to characters in s */
 void itoa(int n, char s[])
 {
    . int i, sign;
 
     if ((sign = n) < 0)  /* record sign */
         n = -n;          /* make n positive */
     i = 0;
     do {       /* generate digits in reverse order */
         s[i++] = n % 10 + '0';   /* get next digit */
     } while ((n /= 10) > 0);     /* delete it */
     if (sign < 0)
         s[i++] = '-';
     s[i] = '\0';
     reverse(s);
 }

Thanks for the answers. It doesn't matter the type either DEC or HEX. Ok so I will try your way septillion.

cesc39

cesc39:
Hi all,

I would like to know how do you display a uint64_t on the monitor display. In fact, it is not possible to display it directly using Serial.print(uint64_t name). I tried to convert it in two uint32_t but I couldn’t success it …

What do you want to do?
Print uint64_t formatted as decimal ASCII?

You’d have to write your own function to do so.
max value is 264 − 1 = 18446744073709551615

Need help doing a function supporting all digits up to max value of uint64_t?
It’s doable.

My way will print it in hex, no problem :)