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=?;
asked May 21, 2016 at 14:43
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.

answered May 21, 2016 at 15:21
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.