Printing 64-bit numbers on the Serial Monitor?

Kuba0040

Well-known member
Hello,
I am currently debugging a program using the Serial Monitor and could really use the ability to print the contents of 64-bit variables in HEX. However, the stock print and println functions don’t seem to work with 64-bit numbers. Do I just have to write my own printing routine or is there something else I can do?

Thank You for the help.
 
You can use the PRIn64 constants. Where n corresponds to the normal printf format constants, d: integer, x: hex, X: hex with large letters...

e.g.:

HTML:
 Serial.printf("64bit hex: 0x%" PRIX64 "\n", 0x01234567'89ABCDEF);

prints:
HTML:
64bit hex:  0x01234567'89ABCDEF
 
Which version of Teensyduino are you using? To check, click Help > About in Arduino.

Print class 64 bit integer printing was added in version 1.54.

printf() has long supported 64 bit integers.

1.56 is the latest.
 
Note I have not tried it with hex output, but have output unsigned.. like:
Code:
      DBGSerial.printf("Storage %d %s %llu %llu\n", ii, qnspi_str[ii], totalSize, usedSize);
Notice the %llu which worked, without, it only first 32 bits were used and stack was not right...
 
Thank You. The "Serial.printf("64bit hex: 0x%" PRIX64 "\n", 0x01234567'89ABCDEF)" method works perfectly.
 
This also works on 1.56, and should work 1.55 and 1.54.

Code:
void setup() {
  while (!Serial) ;
  uint64_t n = 0x123456789ABCDEF;
  Serial.println(n, HEX);
  Serial.println(n);
}

void loop() {
}

capture.png
 
Back
Top