c++arduino-uno

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


I have made a simple bit of code to test a number to see if it is a prime number or not. While feeding it large prime numbers to test the speed of the program on the Arduino, it would only take a number at length 9-/under-digits. I tested my read function, and it returns the entire number but the 'BigNumber' won't parse it; instead, it just says it is 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 tried seeing if anyone has had the same problem as me but I can't find it anywhere.

I'm using an Arduino-Uno

EDIT: after doing some more testing, it now doesn't set the number. Instead 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 specifies the method of finding the result. I also have D=DataCrunch. It checks all the numbers and L=List which creates a list of found Prime numbers like a prime number search, and they work fine except 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.


Solution

  • 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.