简体   繁体   English

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

[英]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 我编写了一段简单的代码来测试一个数字,以查看它是否是质数,但是在向它提供较大的质数以测试arduino上程序的速度时,它只能使用长度为9的数字-/位数不足,我测试了我的读取功能,它返回了完整的数字,但是'BigNumber'不会解析它,表明它只是说它的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 如果我输入10位数字,代码将停止arduino,输出为

<|S 1234567891
>|NUM=1234567891

and if i put a number with 9 digits it outputs as expected 如果我输入一个9位数字,它会按预期输出

<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 我使用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”(10位)后崩溃的次数,这是正常的:

<|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 ?? 但是如果我输入11位数字,它将解析为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. bty:我忘了提到'S number_here'S指定查找结果的方式,我也有D = DataCrunch,它检查所有数字,并且L = List女巫创建一个找到的素数列表,例如素数搜索,然后工作很好,例如DataCrunch(D)在解析给定的数字时存在相同的问题。

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. EDIT2:这证明BigNumber可以在第一篇文章中保存这么大的数字https://forum.arduino.cc/index.php?topic=85692.0

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. 因此,经过大量研究发现,BigNumber不适用于非常大的数字,但是'BigNumber.h'库的另一部分执行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. 但是如您所见,这需要更多的编程才能得到实现,因此即时消息将立即开始,再见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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