Conversion: uint64_t to string

Good day! I've been stuck for a while and I hope you guys can help me.
I have a binary that I was able to convert to a uint64_t. It's big, so I really needed a uint64_t. I'm having trouble converting it to a char array. Can you help me please? I can do it in a standalone project but not on Arduino

Some roadblocks that I encountered:

  • I can't use sprintf ("%llu"): It's giving me a result of 0 and further googling shows that it wasn't really implemented
  • I can't use itoa: Yes, itoa was working for smaller numbers, but i'm dealing with a uint64_t and it seems like it reached its limit and giving me a negative result
  • I can't use String(123456789): I can use it for other types like int and long, but I can't pass in a uint64_t because it's not supported in the parameters
  • I'm having trouble using VC include in Visual Studio: When i go to my Project Properties > Configuration Properties > C/C++ > General > Additional Include Drectories and add in the path "**C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include**" Visual Studio deletes it
    I appreciate any inputs.
    Thanks!

try looking for "long long".

Mark

holmes4:
try looking for "long long".

Mark

Thank you for your reply. Tried searching for that as well, what i saw was just a variation of the uint64_t (eg. using sprintf)

To those having the same problems: I solved my problem here:

Thanks!

I know this is a very old topic but it is one of the top results on Google when looking for a way to print 64bit integers on Arduino and still seems to be a question that doesn't really have a good simple solution. For that reason, I've created a simple library called Int64String for converting 64bit integers to String, which can be used directly with Serial.print() like this:

Serial.println(int64String((int64_t)-9223372036854775808LL));
Serial.println(int64String(4527492349271ULL, 16));

Which would output:

-9223372036854775808
41E2392BD57

It can be found in the Library Manager or at GitHub - djGrrr/Int64String: Arduino library for converting 64bit integers to strings

Thanks. Would have been great if it used character arrays instead of String.

@OP

My curiosity --

When we say unsigned long long int x; (uint64_t x;), the range of x is: 0x0000000000000000 - 0xFFFFFFFFFFFFFFFF. Say, we have a number -- uint64_t x = 0xA123456789123456;. We want string form of this number -- does it mean that we want ASCII codes (0x41, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36) for each of the constituent digits of the given number or ASCII codes (0x31, 0x32, 0x30, 0x30, 0x35, 0x37, 0x35, 0x32, 0x37, 0x34, 0x38, 0x39, 0x30, 0x33, 0x32, 0x36) for each of the constituent digits of the corresponding decimal number?

sterretje:
Thanks. Would have been great if it used character arrays instead of String.

Why not just use the String.c_str() function to get a character array?

GolamMostafa:
@OP

@GolamMostafa - the OP is long, long (no pun intended) gone.

djGrrr:
I know this is a very old topic but it is one of the top results on Google when looking for a way to print 64bit integers on Arduino and still seems to be a question that doesn't really have a good simple solution. For that reason, I've created a simple library called Int64String for converting 64bit integers to String ….

You may think it's old, but your library saved me hours of searching and experimenting with various solutions.

My project involves receiving IR from any remote, then publishing the received code as an MQTT message. From there my Home Assistant or Node-Red can do whatever is needed.

Thanks

Know this is an old thread, but so many odd ways of doing something so simple. Just a little bit banging

int64_t seqNumber = 10000;

Serial.print("Seq: ");
uint32_t low = seqNumberr % 0xFFFFFFFF;
uint32_t high = (seqNumber>> 32) % 0xFFFFFFFF;
Serial.println(low +high);