javascript,jquery,biginteger,jsbn

I'd wanted to give a better answer, but you didn't mention WHICH BigInteger library you were using. // Yes, use the two '..' var a = new BigInteger(5..toString()); // Of if you have a variable var v = 10; var a = new BigInteger(v.toString()); now, with this knowledge you can...

Looking at your code, you have a line bTmp.pow(2). That squares the numbers in your series, but you need to raise bTmp to the bTmp power. Java doesnâ€™t seem to want to take a BigInteger as an argument to pow, but you could replace pow with another for loop. Also,...

What about using setBit to set one bit instead of clearing a lot of bits? private static BigInteger getHighestPowerOf2(BigInteger bigInteger) { int bitLength = bigInteger.bitLength(); return BigInteger.ZERO.setBit(bitLength-1); } ...

java,arrays,long-integer,biginteger

The only real difference between a char and a long is the data size. A char is typically 1 byte, while a long is typically 8 bytes. When you convert a long to a string, you are creating an array of ASCII characters that would represent this number. For example,...

java,while-loop,output,biginteger

No. Why would j revert from 2 to 1? You are only ever adding to it.

c++,algorithm,optimization,biginteger

if you want to avoid bignum libs you can exploit that if you multiply b1 and b2 bits numbers then the result is b1+b2 bits long so just sum the bit count of all multiplicants in a line together and compare that remember the results in some array int bits(DWORD...

Look at that part of your code String s = "test"; byte[] bytes = s.getBytes(); BigInteger message = new BigInteger(s); Now let's have a look at the documentation of the constructor of BigInteger which accept a String. Translates the decimal String representation of a BigInteger into a BigInteger. The String...

java,biginteger,bit-shift,ordinal

BigInteger b =BigInteger.ZERO; b = b.setBit( ordinal() ); You may also use BigInteger.and(BigInteger x). enum OneTwo { one, two, three; BigInteger biValue() { BigInteger bi = BigInteger.ZERO; return bi.setBit(ordinal()); } BigInteger biValue( BigInteger filter ) { BigInteger bi = BigInteger.ZERO; return bi.setBit(ordinal()).and(filter); } } And a test: BigInteger three...

First of all, note that BigInteger is part of java.math and not java.lang, and so would not receive special treatment by the language. All of the boxed types are in java.lang and so the Java language might treat them specially. Such consideration can include boxing, strings in constant pools, class...

java,biginteger,number-theory,modular-arithmetic

Flustered this was put on hold... For the sake of theory, if you wanted to write your own custom method please check the following out, based on a math trick to avoid the computation. First the solution, and then the math behind it. Your subroutine could look something like the...

c#,multithreading,algorithm,biginteger

It depends on the math function but I really can't see how you could speed up basic math functions. For these sort of calculations the next step in the process would typically depend on the previous step in the process. Threading would only really help where you have portions of...

java,comparison,biginteger,bigdecimal

For BigInteger and BigDecimal you should use the compareTo method to check if their value is the same System.out.println(new BigDecimal(BigInteger.valueOf(10)).compareTo(BigDecimal.valueOf(10.0))); ...

Python3 can work on very large numbers (you can say it has almost no limit) and that's automatic. http://stackoverflow.com/a/7604998/3156085 You can try it yourself by entering very large numbers in python shell....

java,types,contains,biginteger

The correct answer will be returned by evaluation of the following: val != null && BigInteger.valueOf(Integer.MIN_VALUE).compareTo(val) < 0 && BigInteger.valueOf(Integer.MAX_VALUE).compareTo(val) > 0 && list.contains(val.intValue()) This will correctly solve the question of whether the BigInteger you have is "contained" within the List<Integer>. Note that here we only downcast where necessary. If...

uint64_t / unsigned long long can store numbers from 0 to 2^64-1, so if you either don't have input of exactly 2^64, or special case handling for it (for example, by setting a boolean and using an alternative formula when necessary), you may get away with using uint64_t. This will...

for example so: count,one := new(big.Int), big.NewInt(1) count.SetString("100000000000000000000000",10) link: http://play.golang.org/p/eEXooVOs9Z...

string,binary,java.util.scanner,biginteger

A string like "hey world" won't have any meaningful numeric representation in base 10, so I suggest to output an appropriate message instead. Scanner scan = new Scanner(System.in); String input = scan.nextLine(); try { BigInteger big = new BigInteger(input); // default constructor is base 10 System.out.println(big.toString(2)); } catch (NumberFormatException){ System.out.println("Input...

First, you should fix your Raw Type (and I'd prefer the List interface) like List<BigInteger> data = new ArrayList<>(); then you need to use set because you can't assign to the return value of a get like that. data.set(i, data.get(i).divide(BigInteger.valueOf(primes[place]))); Also, it's worth noting that BigInteger(s) are (per the Javadoc)...

java,cryptography,biginteger,pow,exponent

You can simplify the code and this will also make it faster x^y / x^z = x^(y - z) so BigInteger yab = y.pow(ab.intValue()); BigInteger ycb = y.pow(cb.intValue()); BigInteger ans = (yab.divide(ycb)).mod(p); can be simplified to BigInteger yabc = y.pow((int) (ab.longValue() - cb.longValue())); BigInteger ans = yabc.mod(p); or BigInteger and...

j.add(BigInteger.valueOf(1)) does not change j. It returns a new BigInteger whose value is one more than j, but you're discarding it. Try j = j.add(BigInteger.ONE) [this constant is provided for you so you don't have to type valueOf(1)]. In fact, BigInteger (like String) is an immutable type, which means there...

java,encryption,cryptography,biginteger

Use new BigInteger(1, data). You are generating negative numbers, RSA only uses positive numbers.

BigInteger is immutable and all operations on it return a new instance instead of modifying the current one. Thus d.add(BigInteger.ONE); does not change the value of d. To fix the issue write: d = d.add(BigInteger.ONE); ...

r,long-integer,biginteger,bigdecimal

All your problems can be solved with Rmpfr most likely which allows you to use all of the functions returned by getGroupMembers("Math") with arbitrary accuracy. Vignette: http://cran.r-project.org/web/packages/Rmpfr/vignettes/Rmpfr-pkg.pdf Simple example of what it can do: test <- mpfr(rnorm(100,mean=0,sd=.0001), 240) Reduce("*", test) I don't THINK it has hypergeometric functions though......

This simplifies to: -(n1-n2-1)/n3 and in Java BigInteger count = n1 .subtract(n2) .subtract(BigInteger.valueOf(1)) .negate() .divide(n3) ...

Not specifically, no. You can create an array with dtype='object', which creates an array of Python objects (including but not limited to ints). This will get you a lot of Numpy array-like functionality but few to none of the performance benefits. Which is to say, an array of Python objects...

c#,encryption,key,rsa,biginteger

When using RSACryptoServiceProvider Private Key is composed of Modulus, Exponent, P, Q, DP, DQ, InverseQ, and D to be set. It is best to load the key from an xml string like: string xmlKey =...

This is because ObjectOutputStream stores objects in Java's serialization format; it does not just store the raw content of the BigInteger object. You can only read the content back by deserializing it, for example with an ObjectInputStream....

c#,encryption,encoding,biginteger,multiplication

The problem is that reversing the arrays is not enough. Because they are unsigned they also require padding depending on the value at the end of the array. If the value at the end of the array is >= 128 the high bit of that value is set and the...

java,cryptography,primes,biginteger,public-key-encryption

I do not hold a degree in crypto, so take this with a grain of salt. You have two major areas of concern here: Your primes need to be unpredictably random. This means that you need to use a source such as SecureRandom to generate your primes. No matter how...

performance,optimization,clojure,numbers,biginteger

You're calculating a lot of HUGE numbers. With B being 500 your keys in the map are 0-499. In find-result with g being 642N you're calculating math/expt 500 times with the largest being (math/expt 642N 249500). This one alone takes a long time to calculate and that's just when k...

The problem here is that 3710... will be interpreted as an int, and so it will be out of range. Essentially what you're trying to do is to create an int, and then convert it to a BigInteger, and the first step of this will fail because an int can't...

c#,math,binary-search,biginteger,newtons-method

Newton's method is N(x) = x - (x^n-a)/(n*x^(n-1))=( (n-1)*x + a/(x^(n-1)))/n This should work well also with integer operations. You may have to correct the result by plusminus 1. It is important to use a good initial value since far away from the root the convergence of Newtons method for...

Your initialization is not correct. BigInteger fact = BigInteger.ONE; This is not optimal. If you just need the single last non-zero digit just keep track only the last non zero digit not the whole multiplied number. let's do some math x x! last-nonzero-digit(x * last-nonzero-digit) 1 1 1*1 => 1...

BigInteger address = new BigInteger(address); if(page >= 512 && page <= 16384){ if(address.compareTo(new BigInteger("0"))>=0 && address.compareTo(max)<=0){ } } ...

There are several problems here. The first one is already in the textual description: to get an element of order 2q (or do you want an element of order q?) the tests must be: If g^2 = 1 mod p, try another number If g^q = 1 mod p try...

Your functions are not equivalent. In the first function, the list of candidates goes to n, and the filter function also uses n for remainder calculation. The second function, however, also uses n for remainder calculation, but the candidates list goes to sqrt(n) instead. To make the second function equivalent,...

performance,cryptography,biginteger,diffie-hellman,modular-arithmetic

64 bit CPUs are significantly faster at big integer arithmetic than 32 bit CPUs. My experience is a factor 2 with identical code and a factor 4 with specialized code. In code written with x86 in mind many intermediate values have 64 bits. For example if you multiply two 32...

When the input number does not fit in long, use the constructor that takes a String argument: String numStr = "453453453456465765234923423094723472394723423482304823095734957320948305712324000123123"; BigInteger num = new BigInteger(numStr); ...

java,string,user-interface,boolean,biginteger

I think you're having an issue here - String output = number + " is" + (BigInteger(input) ? " " : " not ") + "a prime number: " + BigInteger(input); And you want something more like this - String output = num + " is" + (IsPrime(num) ? "...

This is because BigInteger is immutable which means that its value does not change. So first.add(x) will create a new BigInteger containing the computations result, i.e. just reassign the result to first, like first = first.add(...).

Your "for" loop : for (y = x.divide(two); y.compareTo(x.divide(y)) > 0; y = ((x.divide(y)).add(y)).divide(two)); does not terminate. Perhaps you could keep track of the values of the variable 'y', to guess when you have to stop. Edit : that was wrong (see comments). The problem is in the line a...

I suggest you try public static String generateMyUniqueString() { return String.format("%016x", new BigInteger(64, oRandom)); } This will always be 16 digits long as it zero pads the start. BTW: if you generate 4 billion of these ids there is a 50/50 changes two will be the same. Have you considered...

The Forth Scientific Library includes Arithmetic on big signed-magnitude numbers module. Although, a test is required to see what implementation is faster. To use this module in SP-Forth some libraries should be included: REQUIRE [IF] lib/include/tools.f REQUIRE M+ lib/include/double.f S" big.fth" INCLUDED \ just for example In any case, if...

Indeed g^u1 becomes very large. However, you can take advantage of the fact that a * b mod n can be computed as (a mod n * b mod n) mod n Here, a = g ^ u1 and b = y ^ u2, and these computations can be done...

c#,.net,stack-overflow,biginteger,fibonacci

You can use BigInteger without recursion: public static int FibHugesUntil(BigInteger huge1, BigInteger huge2, int reqDigits) { int number = 1; while (huge2.ToString().Length < reqDigits) { var huge3 = huge1 + huge2; huge1 = huge2; huge2 = huge3; number++; } return number; } static void Main(string[] args) { Console.WriteLine(FibHugesUntil(BigInteger.Zero, BigInteger.One, 1000));...

b can't necessarily contain a, only an approximation of it. long double has a larger range than unsigned long long (hence a larger value of max) but might have fewer mantissa bits to hold the most significant bits of the value, giving less precision for large values. The maximum unsigned...

You can create a UNIQUE index on a BLOB column, you simply need to specify a maximum length for the index (which also means, it will only be unique up to that many characters). Consider, however, using VARBINARY instead which allows you to fix the length and means you can't...

new BigInteger(b, 16).toString(); Sample program: public static void main(String[] args) { final BigInteger original = new BigInteger("27"); final String converted = original.toString(16); final BigInteger convertedBack = new BigInteger(converted, 16); System.out.println("original = [" + original.toString() + "]"); System.out.println("converted = [" + converted + "]"); System.out.println("convertedBack = [" + convertedBack.toString() + "]");...

I would use a List<BigInteger> in the first place. There's no need for an ArrayList anymore. Then you can use this LINQ query: var bigIntegers = new List<System.Numerics.BigInteger>(); // fill... byte[][] allByteArrays = bigIntegers.Select(bi => bi.ToByteArray()).ToArray(); Otherwise you need to cast every object in the ArrayList: byte[][] allByteArrays = bigIntegersArrayList.Cast<BigInteger>()...

The computation itself should not take so long. The string creation may take a while, however. This program (Kudos to OldCurmudgeon and http://stackoverflow.com/a/8583188/823393 ) takes approximately 3.9 seconds on a Core I7, 3GHz, Java 7/21, when started with -Xmx1000m -sever: import java.lang.reflect.Constructor; import java.lang.reflect.Method; public class FastBigInteger { public static...

With C++11, we can make User-defined literals Largeint operator "" _largeint(const char* literal_string) { Largeint largeint; // initialize largeint with literal string content; return largeint; } or, if you prefer the variadic template template<char... Cs> Largeint operator "" _largeint(); And then use it: Largeint largeint = 123456789012345678901234567890_largeint; You may use...

It's impossible to reverse this multiplication. First, let's take the two's complement of the first number. 3904635256 = 2147483648 - -1757151608 Next, we'll multiply the second number 369018468323820520 = 3904635256 * 94507795 Now, here's the tricky part. We convert the product to hex, and drop the digits larger than a...

The reason you are getting only 422 distinct elements is that your values are so large and you're casting them to an int. When the result of Math.pow(i, j) (a double) is larger than Integer.MAX_VALUE and you cast to an int, then the result is Integer.MAX_VALUE. Section 5.1.3 of the...

c#,.net,.net-4.0,ado.net,biginteger

BigInt does not correspond to BigInteger. It corresponds to long/Int64. You should probably remove all BigInteger usages from your business code and use long. ADO.NET does not understand BigInteger.

java,precision,biginteger,bigdecimal,largenumber

Using BigDecimal and doing calculation in double is the same as not using BigDecimal at all. Use BigDecimal to do calculations: BigDecimal bigNumber = new BigDecimal(1000).pow(10); System.out.println(bigNumber); ...

Use bitLength() (source) The java.math.BigInteger.bitLength() returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit. For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation. BigInteger bi; bi = new BigInteger("778674"); System.out.println("length: " + bi.bitLength()); ...

java,binary,long-integer,biginteger

You are counting the bits wrong: public void test() { long value = 0x4000863; //This value is actually read from a file long bigger = 0x8000000000000000L; BigInteger test = new BigInteger(Long.toString(value)); System.out.println("L:" + Long.toBinaryString(value) + "\r\nB:" + test.toString(2) + "\r\nB63:" + test.testBit(63)); test = new BigInteger(Long.toString(bigger)); System.out.println("L:" + Long.toBinaryString(bigger) +...

toByteArray() returns a two's complement form of the BigInteger (internally BigInteger uses signed two's complement ints), which may have a leading padding zero byte to preserve signedness. When using BigInterger with unsigned values it may be easier to instead use toString(2) or toString(16) which would avoid padding, but necessitate string...

javascript,algorithm,biginteger

//r = b1 % b2 a different approach is to operate modulus by parts (say your limit for a number is 9 digits per number and say b2 < 100): Starting from the leftmost digit of b1, construct a number using the first 9 digits and call it N. Calculate...

You can use .bitCount() on the BigInteger. Unless you need to solve it manually, in which case you can use normal Java bitwise operations.

This'll work: public static void primeGenerator() { BigInteger[] primeList = new BigInteger[10]; BigInteger startLine = new BigInteger("1"); int startPower = 1; BigInteger endLine = new BigInteger("10"); int endPower = 2; int j = 0; for (BigInteger i = startLine.pow(startPower); i.compareTo(endLine .pow(endPower)) <= 0; i = i.add(BigInteger.ONE)) { if (checkPrimeFermat(i) ==...

java,java.util.scanner,biginteger,inputmismatchexception

Oracle says public class InputMismatchException extends NoSuchElementException Thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type, or that the token is out of range for the expected type. public class NumberFormatException extends IllegalArgumentException Thrown to indicate that the application has...

You need to prepend a 0 to the string. While this number works with long.Parse, with BigInt you get a negative number if the first digit is between 8-F string hex = "09782E78F1636"; BigInteger b1 = BigInteger.Parse(hex,NumberStyles.AllowHexSpecifier); Console.WriteLine(b1); ...

This is not very difficult to do without using external libraries. Store the digits of the number in a vector and multiply digit by digit (like you do in paper). Example: power(12,23): Store as start->1->2->end step 1 result: start->1->4->4->end step 2 result: start->1->7->2->8->end and so on... ...

This is an x64 jitter optimizer bug in .NET 4.0 through 4.5.2. Characterizing it is fairly difficult, the codegen is pretty heavy due to the BigInteger usage. The x64 jitter has had a history of optimizer bugs for struct types, like BigInteger, so that's the probable underlying cause. The combination...

You have your carry and your digit reversed (when there is a carry).

For that loop to break, it must reach 10^30 ~= 2^100. Sum of the squares of the first n natural numbers is approximately equal to n^3. So your loop will break approximately when i becomes 10^10 ~= 2^33. I guess int i is 32-bit so you MIGHT be are overflowing...

c++,list,stl,operator-overloading,biginteger

if (rit1 > rit2) should be if (*rit1 > *rit2) as you want to compare the contents of the iterators not the iterator themself.

c++,operator-overloading,biginteger

The immediate problem is that you're returning a pointer to an automatic (i.e. function-local) variable. The variable goes out of scope the moment the function returns. Dereferencing the returned pointer would lead to undefined behaviour. I would argue that the method's signature should look like this: class BigInt { BigInt...

That's because BigInteger is not, in fact, anything that is close to being a primitive. It is implemented using an array and some additional fields, and the various operations include complex operations. For example, here is the implementation of add: public BigInteger add(BigInteger val) { if (val.signum == 0) return...

java,multithreading,primes,biginteger

this.num = num; in your constructor does nothing (there is no parameter num, so you are assigning this.num the value of itself). num is still null. You need to initialize it.

I suggest you use BouncyCastle and create an AsymmetricCipherKeyPair; here is an example I adapted from RSA using BouncyCastle public static AsymmetricCipherKeyPair generateKeys(int keySizeInBits) { RSAKeyPairGenerator kpg = new RSAKeyPairGenerator(); kpg.init(new KeyGenerationParameters(new SecureRandom(), keySizeInBits)); return kpg.generateKeyPair(); } ...

The version of EncryptedInteger you link to isn't the one you're using. The one you're using is this one (The current version). The difference is that it includes this line: private Class bigi; And it assigns BigInteger.class to it. Gson can't serialize that, and that's what is throwing that exception....

Scientific notation applies to BigIntegers only in a limited scope - i.e. when the number in front of E is has as many or fewer digits after the decimal point than the value of the exponent. In all other situations some information would be lost. Java provides a way to...

You can use pg_column_size, it'll give you bytes size of bigint. Using it you can get its max and min sizes: select (2^(8*pg_column_size(1::bigint)-2))::bigint << 1 as min_bigint_value; select -(((2^(8*pg_column_size(1::bigint)-2))::bigint << 1)+1) as max_bigint_value; So if somehow in the future bigint max value will change (very very very unlikely) your code...

You're using Mono version which is an equivalent of .NET 3.5, but the System.Numerics is available in .NET 4.0+ only. I'm afraid that you have to add a third party library to your project. Unity3d doesn't have BigInteger implementation. This one: biginteger.codeplex.com should be fine....

math,cryptography,biginteger,plc,iec61131-3

Suppose your maximal integer size is 64 bit. Strings are not that useful for doing math in most languages, so disregard string types. Now choose an integer of half that size, i.e. 32 bit. An array of these can be interpreted as digits of a number in base 232. With...

javascript,highcharts,highstock,biginteger,bigint

This case is not related with highcharts, because it is default problem in javascirpt. See the example: alert(123456789123456789123456789); http://jsfiddle.net/Lawg4/ In the alert, you will notice that javascript return with epsilon. Related topic: Javascript BigInt.js How to Divide big numbers...

I think this line is an error: if(a[j]>=pow(10,(j+1))){ I don't know if it's the error or the only error. This says 'If the j-placed digit is greater than or equal to 10^(j+1)'. I think the carry test is just 'is the j-place digit greater than or equal to 10. The...

TL;DR build a carry-lookahead adder where each individual additionner adds modulo radix, instead of modulo 2 Additions need incoming carries The problem in your model is that you have a rippling carry. See Rippling carry adders. If you were in an FPGA that wouldn't be a problem because they have...