Skip to content
Advertisement

Tag: biginteger

How do I prevent a long overflow?

My assignment ask us to ask the user to enter a number and print the factorial of it, it also ask us to not allow the user to chose any negative number or number over 25, when they do, we loop them back to scanner to re renter a number we were also told to store the number in a

BigInteger.isProbablePrime seems much more certain than it says it is

I understand the certainty argument to mean: certainty – a measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 – 1/2certainty) From my experiments, it seems to exceed it by quite a lot! The code below finds “probable primes” between 2 and 1 million

Something wrong with BigInteger

when i test this function with base16 :F0F0F0F0F0F0F0, it return right result = 67818912035696880 BUT when i test with base16: F0F0F0F0F0F0F0F0, it returns wrong result: 17361641481138401580 which right result must be 17361641481138401520 please help me! Answer Math.pow delivers a double, 8 bytes. So from some huge double value, it becomes imprecise in the less significant digits. You could have used

Is there a way to pow 2 BigInteger Numbers in java?

I have to pow a bigInteger number with another BigInteger number. Unfortunately, only one BigInteger.pow(int) is allowed. I have no clue on how I can solve this problem. Answer I have to pow a bigInteger number with another BigInteger number. No, you don’t. You read a crypto spec and it seemed to say that. But that’s not what it said;

BigInteger.intValue() equivalent in C#

I am trying to translate a java code into C# and encountered a problem working with BigInteger operations. I found several resources on BigInteger implementation in C# and the intValue itself. But no clue on BigInteger.intValue equivalent in C#. The definition in Java is: Converts this BigInteger to an int. Thisconversion is analogous to a narrowing primitive conversion from long

Java BigInteger alternative

Is there a way to improve BigInteger performance with caching? When you operate on BigInteger it always creates a new BigInteger. For example, when you multiply two big integers, a new BigInteger is created to host the result. I want to use some mutable version of a BigInteger that will update one of the fields with the result. Answer There

Fibonacci calculator with BigIntegers

I’m working on a homework project where I must have the user input a number, and the computer spits out the Fibonacci numbers up to that one. I’d normally be able to do this, with int values, except that for this program, I need to use the BigInteger type instead, because int, long, double, etc. types are too small to

Get a BigInteger attribute from Cassandra ResultSet

I’m trying to get the number of key value pairs in a Cassandra column family. Following is the code I used. But when I ran this code, I’m getting following exception. According to datastax documentation (http://www.datastax.com/drivers/java/2.0/com/datastax/driver/core/Row.html) getVarint should return a BigInteger. So why I am getting a exception here? What an I doing wrong? Answer You can get value as

Advertisement