0

i want to convert string for example "68976543210" to unsigned long long(64 bit) in mega2560, do is possible?

String x="68976543210";
unsigned long long y=?;
0

1 Answer 1

3

avr-libc lacks strtoull() that I would normally use for such a conversion. You will have to do it manually.

Fortunately it's quite simple - just start with y=0 and, for each character in the string, multiply y by 10 then add the numeric value of the character in the string:

String x = "68976543210";
unsigned long long y = 0;

for (int i = 0; i < x.length(); i++) {
    char c = x.charAt(i);
   if (c < '0' || c > '9') break;
   y *= 10;
   y += (c - '0');
}

Note that the Arduino Print API has no method for printing a 64-bit integer.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.