biginteger

Trouble with OpenSSL's BN_bn2bin function

I'm trying to use the BN_* functions in OpenSSL. Specifically, I have the following code: #import <openssl/bn.h> BIGNUM * num = BN_new(); BN_set_word(num, 42); char * buffer = malloc((BN_num_bytes(num)+1) * sizeof(char)); buffer[BN_num_bytes(num)] = '\0'; int len = BN_bn2bin(num, buffer); printf("42 in binary is %s\n", buffer); Howev...

Calculating very large whole numbers

I am trying to compute 2^1000 (2 to the power of 1000) using c#. I need the value to all places. I've been scratching my head for a while now because I can't seem to figure out a way to achieve this in c#. Is there some kind of type that will store a number 300+ digits long, that I'm missing? :) Thanks ...

How to check for division by 7 for big number in C++?

I have to check, if given number is divisible by 7, which is usualy done just by doing something like n % 7 == 0, but the problem is, that given number can have up to 100000000, which doesn't fit even in long long. Another constrain is, that I have only few kilobytes of memory available, so I can't use an array. I'm expecting the numbe...

Problems with java.math.BigInteger

I have the following code at the head of a method: BigInteger foo = BigInteger.valueOf(0); BigInteger triNum = BigInteger.valueOf(0); //set min value to 1*2*3*4*5*...*199*200. BigInteger min = BigInteger.ONE; BigInteger temp = BigInteger.ZERO; for(int i=1; i<=200; i++) { temp = BigInteger.valueOf(i); min = min.multiply(temp); }...

Is BigInteger immutable or not?

In .NET 4 beta 2, there is the new Numerics namespace with struct BigInteger. The documentation states that it is an immutable type, as I would have expected. But I'm a little confused by the post-increment operator (++). This defintely seems to mutate the value. The following while-loop works: static BigInteger Factorial(BigInteger ...

Can I construct a BigInt with any byte array (Scala)?

I'm trying to represent the result of an MD5 hash in the shortest possible string. It seems a waste to just turn it into a hex string and let G through Z go to waste. One idea I have had is getting the MD5 hash of my input as an array of bytes and constructing a BigInt with it. I can then call toString(36), and get the number as a base-...

Java/Scala BigInteger Pasting

I have a problem with the Java BigInteger class: I can't paste a large value into BigInteger. For example, let's say I want to assign a BigInteger to this number: 26525285981219105863630848482795 I cannot assign it directly, because the compiler thinks it's an integer: val bi = 26525285981219105863630848482795 //compile error But I...

Java: How to use BigInteger?

I have this piece of code, which is not working: BigInteger sum = BigInteger.valueOf(0); for(int i = 2; i < 5000; i++) { if (isPrim(i)) { sum.add(BigInteger.valueOf(i)); } } The sum variable is always 0. What am I doing wrong? ...

Java BigInteger prime numbers

I a m trying to generate a random prime number of type BigInteger, that is between an min and max value which I supply. I am aware of the BigInteger.probablePrime(int bitlength, random), but I am not sure how or even if the bitlength translates into a max/min value of the outputted prime. Thanks, Steven1350 ...

Division of big numbers

I need some division algorithm which can handle big integers (128-bit). I've already asked how to do it via bit shifting operators. However, my current implementation seems to ask for a better approach Basically, I store numbers as two long long unsigned int's in the format A * 2 ^ 64 + B with B < 2 ^ 64. This number is divisible by 2...

big integers in c++

I know this question has probably been asked in this forum many times and in the web as well. I am asked to create an implementation of a big integer in c++, however there is a constraint that one of my constructor should take an int as an argument... so I am guessing there will be more than one non-default constructor... so my question ...

big integers with fixed length

I am looking for a library for big integers but with fixed width (128 or 256 would be enough). The reason is I don't want any allocation on the heap. I tried to make them myself but implementing multiplication, division and modulo an efficient way seems to be quite a pain. Does this already exists somewhere ? Thanks ...

Handling large integer on C/C++ using Visual C++ 2008

How do I do to handles some big positive integers (like 9,999,999,999) on Visual C++ 2008 on a 32-bit PC. Please give an example on declaring, printf, scanf of these big positive integers. Please consider using 9,999,999,999 in your example. ...

Is there a substitute for Pow in BigInteger in F#?

I was using the Pow function of the BigInteger class in F# when my compiler told me : This construct is deprecated. This member has been removed to ensure that this type is binary compatible with the .NET 4.0 type System.Numerics.BigInteger Fair enough I guess, but I didn't found a replacement immediately. Is there one? Sho...

Python long multiplication

I'm in need of an algorithm faster than the current normal python long multiplication , I tried to find a decent karatsuba implementation , but I can't. def main(): a=long(raw_input()) if(a<0): a=a*-1 a=((a*(a+1)/2)-1) print(-a) else: a=(a*(a+1))/2 print(a) main() As you see , it's nothing complica...

Java: BigInteger, howto write it thru an OutputStream

Hi, I want to write a BigInteger to a file. What is the best way to do this. Of course I want to read (with the program, not by human) it from an inputstream. Do I have to use an ObjectOutputStream or are there better ways? The purpose is to use as less bytes as possible. Thanks Martijn ...

Regarding java.math.BigInteger

The problem im facing with BigInteger when i try computing a string like "7+3" and then storing the result in a BigInteger variable, it throws a NumberFormat exception. Any pointers on how this can worked on? Eg: String ist="7+2"; java.math.BigInteger a = new java.math.BigInteger(ist); ...

Printing Binary(byte) value in File

Hi the below code print the biginteger to a file in decimal format ,how do i convert the code into printing binary data and hex data into the File instead ?? static void print_pos( FILE* f, bigint bi ) { if ( bi_compare( bi_copy( bi ), bi_10 ) >= 0 ) print_pos( f, bi_int_divide( bi_copy( bi ), 10 ) ); putc( bi_int_mo...

Java workaround for BigInteger

I was working on a scenario wherein i had to implement BODMAS in Java and the operands could have as many as 1000 digits. So i chose to implement it in the following manner - I converted the infix expression (expression on which BODMAS was to be implemented) to postfix And then i evaluated the postfix expression by parsing every BigInt...

Django, BigIntegerField, and django.contrib.auth.user.id

Django now provides a BigIntegerField for use in django models (available in svn trunk and also 1.2 alpha-1 release). I need my django.contrib.auth.user model to have a BigIntegerField as its auto-incrementing primary key, whereas it currently uses an auto-incrementing IntegerField as its primary key. Also, wherever contrib.auth.user is...