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=?;
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityi 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=?;
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.