BigNumber.h Arduino 如何解析大于 10 位的数字

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

我编写了一些简单的代码来测试一个数字,看看它是否是素数,但是在给它输入大的素数来测试 arduino 上程序的速度时,它只需要一个数字在长度为 9-/under-digits 我测试了我的读取功能并且它 returns 整个数字但是 'BigNumber' 不会解析它 insted 它只是说它的 0

代码:

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

如果我输入一个 10 位数字,代码会停止 arduino,输出是这样

<|S 1234567891
>|NUM=1234567891

如果我输入一个 9 位数字,它会按预期输出

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

我试过看看有没有人遇到过和我一样的问题,但我到处都找不到。

我使用 arduino-uno

编辑:在做了更多测试后,它现在没有设置测试后崩溃的数字 'S 1111111111'(10 位)它的输出是正常的:

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

但如果我输入 11 位数字,它会解析为 0 ??

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

bty: 我忘了提到 'S number_here' S 指定了查找结果的方法我也有 D=DataCrunch 它检查所有的数字和 L=List 创建一个找到的列表素数就像素数搜索,除了 DataCrunch (D) 在解析给定数字时存在同样的问题外,它们工作正常。

编辑2: 这证明 BigNumber 可以容纳如此大的数字 https://forum.arduino.cc/index.php?topic=85692.0 在第一个 post.

所以经过一些广泛的研究后发现 BigNumber 不适合非常大的数字,但 'BigNumber.h' 库的另一部分执行它的 bc_num.

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

输出

Controll=9898989898

但是如您所见,这需要更多的编程才能实现,所以我要开始了,再见。