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. I can do it in a standalone project but not on Arduino
Some roadblocks that I encountered:
Any input is greatly appreciated.
Assuming you want to print "number" in HEX:
uint64_t number;
unsigned long long1 = (unsigned long)((number & 0xFFFF0000) >> 16 );
unsigned long long2 = (unsigned long)((number & 0x0000FFFF));
String hex = String(long1, HEX) + String(long2, HEX); // six octets
Just to add onto the list of possible solutions. I use the following function:
char *uint64_to_string(uint64_t input)
{
static char result[21] = "";
// Clear result from any leftover digits from previous function call.
memset(&result[0], 0, sizeof(result));
// temp is used as a temporary result storage to prevent sprintf bugs.
char temp[21] = "";
char c;
uint8_t base = 10;
while (input)
{
int num = input % base;
input /= base;
c = '0' + num;
sprintf(temp, "%c%s", c, result);
strcpy(result, temp);
}
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With