Ask Your Question
2

How can uint64_t be printed using Serial in Arduino?

asked 2022-05-04 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-08-19 05:00:00 +0000

plato gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-04 11:00:00 +0000

Seen: 25 times

Last updated: Aug 19 '22