Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are different ways to print a uint64_t using Serial in Arduino, depending on the desired format of the output. Here are some examples:

  1. Using Serial.print():
uint64_t myNumber = 18446744073709551615;
Serial.print(myNumber);

This will print the uint64_t value as a sequence of ASCII characters, which may not be readable or accurate for very large numbers.

  1. Using Serial.write():
uint64_t myNumber = 18446744073709551615;
byte* numberBytes = (byte*)&myNumber;
for(int i=0; i<8; i++){
  Serial.write(numberBytes[i]);
}

This will print the uint64_t value as a raw byte sequence, which can be useful for data transmission or debugging, but is not human-readable.

  1. Using a library for bigintegers:

There are several libraries that support arbitrary-precision integers (bigintegers) in Arduino, such as Bigint or BigInteger. These libraries allow operations on uint64_t and larger integers, and also provide functions for formatting and printing these values. For example:

#include <Bigint.h>
Bigint<16> myNumber("18446744073709551615");
Serial.println(myNumber.toString());

This will print the uint64_t value as a string in decimal notation, which can be read and processed easily.

Note that printing uint64_t values may require more memory than other data types, and may also affect the performance of the Arduino board. It's recommended to check the available memory and optimize the code accordingly.