biginteger

Why types at System.Numerics shows empty at Reflector?

I opened System.Numerics at reflector to study how it works. But all methods at BigInteger and Complex are empty. Why? How can this works? ...

Handling arbitrarily large integers in dbase language

Is there a simple package available that permits programming in xbase ( i.e. dbase or Foxpro syntax) and has a datatype to store and perform simple arithmatical operations on arbitrarily large integers ( say 100,000 decimal digits) ? ...

What is the most effective way to create BigInteger instance from int value?

I have a method (in 3rd-party library) with BigInteger parameter: public void setValue (BigInteger value) { ... } I don't need 'all its power', I only need to work with integers. So, how can I pass integers to this method? My solution is to get string value from int value and then create BigInteger from string: int i = 123; setValue ...

Django BigInteger auto-increment field as primary key?

Hi all, I'm currently building a project which involves a lot of collective intelligence. Every user visiting the web site gets created a unique profile and their data is later used to calculate best matches for themselves and other users. By default, Django creates an INT(11) id field to handle models primary keys. I'm concerned with ...

Check if BigInteger is not a perfect square

I have a BigInteger value, let's say it is 282 and is inside the variable x. I now want to write a while loop that states: while b2 isn't a perfect square: a ← a + 1 b2 ← a*a - N endwhile How would I do such a thing using BigInteger? EDIT: The purpose for this is so I can write this method. As the article states one must chec...

BigInteger in Silverlight

How would I be able to get a "BigInteger" class for use in Silverlight? ...

J2ME passing string value to bouncy castle BigInteger

I passed a string "654782" to the BigInteger constructor, but when I read the integer back I got a different number. String modulus_str = "654782"; BigInteger modulus = new BigInteger(modulus_str); modulus.toString() returns a different value ...

BitShifting with BigIntegers in Java

I am implementing DES Encryption in Java with use of BigIntegers. I am left shifting binary keys with Java BigIntegers by doing the BigInteger.leftShift(int n) method. Key of N (Kn) is dependent on the result of the shift of Kn-1. The problem I am getting is that I am printing out the results after each key is generated and the shiftin...

Mapping a BigInteger to a circle

I have a C# system using 160 bit numbers, stored in a BigInteger. I want to display these things on a circle, which means mapping the 0->2^160 range into the 0->2Pi range. How would I do this? The approach that jumps instantly to mind is BigInteger number; angle = (number / pow(2, 160)) * TwoPi; However, that has complexities because...

BigInteger or not BigInteger?

In Java, most of the primitive types are signed (one bit is used to represent the +/-), and therefore when I am exceed the limits of this type, I can get many strange things, like negative numbers. In the BigInteger class, I have no limits and there are some helpful functions there but it is pretty depressing to convert your beautiful c...

Why doesn't my implementation of ElGamal work for long text strings?

I'm playing with the El Gamal cryptosystem, and my goal is to be able to encipher and decipher long sequences of text. El Gamal requires the plaintext to be an integer. I have turned my string into a byte[] using the .getBytes() method for Strings, and then created a BigInteger out of the byte[]. After encryption/decryption, I turn t...

How do you raise a Java BigInteger to the power of a BigInteger without doing modular arithmetic?

I'm doing some large integer computing, and I need to raise a BigInteger to the power of another BigInteger. The .pow() method does what I want, but takes an int value as an argument. The .modPow method takes a BigInteger as an argument, but I do not want an answer congruent to the value I'm trying to compute. My BigInteger exponent i...

Generating exactly prime number with Java

Hi, I'm aware of the function BigInteger.probablePrime(int bitLength, Random rnd) that outputs probably prime number of any bit length. I want a REAL prime number in Java. Is there any FOSS library to do so with acceptable performance? Thanks in advance! EDIT: I'm looking at 1024 & 2048 bit primes. ...

How can I add two arbitrarily large numbers using only stack allocated memory in C++?

How can I write a program that adds two arbitrarily large numbers using stack allocated memory in C++? I am not allowed to use dynamic allocations on the heap such as malloc or new. ...

java.math.BigInteger pow(exponent) question

Hi, I did some tests on pow(exponent) method. Unfortunately, my math skills are not strong enough to handle the following problem. I'm using this code: BigInteger.valueOf(2).pow(var); Results: var | time in ms 2000000 | 11450 2500000 | 12471 3000000 | 22379 3500000 | 32147 4000000 | 46270 4500000 | 31459 5000000 | 49922 See? 2,5...

BigInteger.Parse() on hexadecimal number gives negative numbers.

I've started using .NET 4 System.Numerics.BigInteger Structure and I've encountered a problem. I'm trying to parse a string that contains a hexadecimal number with no sign (positive). I'm getting a negative number. For example, I do the following two asserts: Assert.IsTrue(System.Int64.Parse("8", NumberStyles.HexNumber, CultureInfo.In...

BigInteger.ToString() returns more than 50 decimal digits.

I'm using .NET 4 System.Numerics.BigInteger Structure and I'm getting results different from the documentation. In the documentation of BigInteger.ToString() Method It says: The ToString() method supports 50 decimal digits of precision. That is, if the BigInteger value has more than 50 digits, only the 50 most significant di...

Extremely big integer multiplication and addition

Greetings, I need to multiply two extremely long integer values stored in a text file (exported via GMP (MPIR, to be exact), so they can be any in any base). Now, I would usually just import these integers via the mpz_inp_str() function and perform the multiplication in RAM, however, these values are so long that I can't really load the...

java: how for loop work in the case of BigInteger

I want to take Input from the user as Big-Integer and manipulate it into a For loop BigInteger i; for(BigInteger i=100000;i<=1;i--){ i=i+i; } But it won't work can any body help me. ...

how to convert BigInteger to String in java

i converted a string to BigInteger as follows: Scanner sc=new Scanner(System.in); System.out.println("enter the message"); String msg=sc.next(); byte[] bytemsg=msg.getBytes(); BigInteger m=new BigInteger(bytemsg); now i want my string back.i m using m.toString() method but not getting desired result. why??? wh...