简体   繁体   中英

BigNumber.h Arduino how to parse a number larger then 10 digits

i have made a simple bit of code to test a number to see if it is a prime number or not but while feeding it large prime numbers to test the speed of the program on the arduino it whould only take a number at length 9-/under-digits i tested my read function and it returns the entire number but the 'BigNumber' wont parse it insted it just says its 0

code:

void Speed(String num)
{
    Serial.println("NUM="+num);
    BigNumber NUM = num.c_str();//this is where it fails
    BigNumber Curr = "1";//start 2 / 'curr++' start of loop
    num = "";
    ... the testing of prime numbers here

the code stops the arduino if i put a 10 digit number in, the output is so

<|S 1234567891
>|NUM=1234567891

and if i put a number with 9 digits it outputs as expected

<S 123456789
>|NUM=123456789
>|123456789 is not a prime number 
>|because ist a factor of 3

i have tryed seeing if anyone has had the same problem as me but i cant find it anywhere.

im use an arduino-uno

EDIT: after doing some more testing it now doesnt set the number insted of crashing after testing 'S 1111111111' (10 digits) its output is normal:

<|S 1111111111
>|NUM=1111111111
>|1111111111 is not a prime number 
>|because ist a factor of 11

but if i put in 11 digits it parses as 0 ??

<|S 11111111111
>|NUM=11111111111
>|0 cant be a prime number because it doesn't end in 1,3,7,9

bty: i forgot to mention that 'S number_here' S specifys the mothod of finding the result i also have D=DataCrunch it checks all the numbers and L=List witch creates a list of found Prime numbers like a prime number search, and thay work fine exept that DataCrunch (D) has the same problem with parsing the number given.

EDIT2: this is proof that BigNumber can hold such a large number https://forum.arduino.cc/index.php?topic=85692.0 in the first post.

so as it turns out after some extensiv research that BigNumber is not fit for very large numbers but another part of the 'BigNumber.h' lib does its bc_num.

bc_num x;
bc_str2num(&x, "9898989898", 10);
String c = "Controll=";
c+=bc_num2str(x);
Serial.println(c);

output

Controll=9898989898

but as you can see this takes a bit more programming to get implamented and so im going to go off and start now bye.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM