Java Big Integer Value
10 次查看(过去 30 天)
显示 更早的评论
I was working with BigIntegers to solve a problem on Cody, where I got stuck upon something.
import java.math.*
BigInteger(10)
BigInteger(1234)
BigInteger(num2str(1234))
I tried to find why this happens but I couldn't find any useful resources. I have no knowledge of Java if anyone needs to know.
Is the default input to BigInteger a string/character array? (Which I suspect so)
Also an odd behaviour (which I don't understand)? Can someone explan why this happens?
for i=1:11
BigInteger(2^i+1)
end
0 个评论
采纳的回答
Walter Roberson
2022-2-1
The single-parameter form of BigInteger with a numeric parameter is
Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger."
So when you pass in a numeric value, it converts the numeric value to a signed byte.
When you pass in the result of num2str() you are using a different constructor,
Translates the decimal String representation of a BigInteger into a BigInteger."
5 个评论
Walter Roberson
2022-2-15
One byte holds 8 bits, and 2^8 = 256 .
The BigInteger class always uses full bytes -- you cannot define a BigInteger that is (for example) 11 bits long
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!