biginteger « biginteger « Java Data Type Q&A





1. Why is BIGInteger in JAVA not responding for higher powers?    stackoverflow.com

When I try to find the value of BigInteger data type for 2 to power 23,000, I am not able to see the value. Upto 2 to power 22000, I could ...

2. Why can Haskell handle very large numbers easily?    stackoverflow.com

Hugs> 94535^445
1376320882321377050696053887661515621104890164005282153069726424773999801846841903244827702943487982707454966009456016735041878000604143500908532887464920380605164932112687039059526672109818924234920844448231612532570718657160234177285377733830104834041049076609912488237219608445995072867798430614935403219495883835042862802917980856774134757390782052200512932375660858045003581611863121089979673784484701791210379500218604466721285456487387736825167702127154268533859979529612671925052419513844416493584817268143587955662039327860394141299238613042312035808541735213479394437496215520277526351425482512084759462579494878772787079101513841720202004639843443083454387175700954018825292148776647553122504118229978165851660083576570848983047255050145168802863168613110619584686348869690774233051669081248424584219383477237544209892290799448207462345346336076966775224683516220960618177284844330167142846351091001423033864986042919757795382577032341453971393897073354841924 

3. Java: How to use BigInteger?    stackoverflow.com

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)) {
     ...

4. Java workaround for BigInteger    stackoverflow.com

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 ...

5. What complexity are operations on Java 7's BigInteger?    stackoverflow.com

What complexity are the methods multiply, divide and pow in BigInteger currently? There is no mention of the computational complexity in the documentation (nor anywhere else).

6. What data-structure should I use to create my own "BigInteger" class?    stackoverflow.com

As an optional assignment, I'm thinking about writing my own implementation of the BigInteger class, where I will provide my own methods for addition, subtraction, multiplication, etc. This will be ...

7. Switch to BigInteger if necessary    stackoverflow.com

I am reading a text file which contains numbers in the range [1, 10^100]. I am then performing a sequence of arithmetic operations on each number. I would like to use ...

8. BigInteger or not BigInteger?    stackoverflow.com

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 ...

9. biginteger calculation problem    stackoverflow.com

I am using the following code but the parameters are not passed to the methods.

BigInteger p = BigInteger.valueOf(0);
BigInteger u1 = obj.bigi_calc(g1, l);
In this g1,l are long values. The method is
private BigInteger bigi_calc(long ...





10. java: how for loop work in the case of BigInteger    stackoverflow.com

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. ...

11. Get the integral part of a BigFraction, as a BigInteger    stackoverflow.com

What is an easy way to get the integral part of a BigFraction as a BigInteger? Basically I want the same result that the intValue and longValue methods ...

12. Optimise arithmetic operations on very large numbers    stackoverflow.com

I want to compute the function H(n) where

H(0)=0;
H(i)=H(i-1)×A+Ci mod B;

10<=A,B<=10^15;
C is an array of n elements But it is taking too much time...any better way of doing this..Please help
public BigInteger H(int no)
 ...

13. Creating a BigInteger Method    stackoverflow.com

Is there any way to create a BigInteger Method? I want to have a method of return type BigInteger.

14. Using BigInteger Multiply operator    stackoverflow.com

I was wondering if there was a way to multiply BigInteger variables together, because the * operator cannot be applied to BigInteger. So I was wondering if it was possible to ...

15. Java, comparing BigInteger values    stackoverflow.com

BigInteger bigInteger = ...;


if(bigInteger.longValue() > 0) {  //original code
    //bigger than 0
}

//should I change to this?
if(bigInteger.compareTo(BigInteger.valueOf(0)) == 1) {
    //bigger than 0
}
I need to ...

16. java using BigInteger and While    stackoverflow.com

I have a problem

import java.math.BigInteger;
import java.io.*;
import java.util.*;
import java.lang.*;

public class medici {
   public static void main(String[] arg)  {
{     

  BigInteger zac = new ...





17. Exponentiation of a Java BigInteger with a value lower than 1    stackoverflow.com

Possible Duplicate:
How to do a fractional power on BigDecimal in Java?
I have a BigInteger A that I need to exponentiate with 1/b (b is ...

18. how can I use biginteger in java    stackoverflow.com

i have this code and i want to change it to BigInteger

import java.util.*;
public class Euclid {
    long TIME;
    long start = System.currentTimeMillis();
    ...

19. BigInteger Homework Help Needed    stackoverflow.com

I have been told I have to write a BigInteger class, I know there is one, but I have to write my own. I am to take either ints or a ...

20. How does BigInteger store its data?    stackoverflow.com

I've been searching around for quite a while, and I've found almost nothing on how BigInteger actually holds its numbers. Are they an array of chars? Something else? And how is ...

21. OutOfMemoryError on BigInteger    stackoverflow.com

I'm writing a polish notation calculator for BigIntegers (just *, ^ and !) and I'm getting an OutOfMemoryError on the line where I'm subtracting BigInteger.ONE to get the factorial to work, ...

22. Implementing BigInteger's multiply...from scratch (and making sure it's O(n^2))    stackoverflow.com

As homework, I'm implementing Karatsuba's algorithm and benchmarking it against a primary-school-style O(n^2) multiplication algorithm on large integers. I guessed my only choice here was to bring the numbers to their ...

23. How do i compare values of BigInteger to be used as a condition in a loop?    stackoverflow.com

I am trying to compare if the value of one BigInteger(base) is > the value of another BigInteger(prime) and if the value of 'a' is not equal to one. If ...

24. NumberFormatException, BigInteger in java    stackoverflow.com

Getting following run-time error

C:\jdk1.6.0_07\bin>java euler/BigConCheck
Exception in thread "main" java.lang.NumberFormatException: For input string: "z
"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.
java:48)
        ...

25. Modulus not positive :BigInteger    stackoverflow.com

error ---Modulus not positive BigInteger is taking vaule 0, or -ve, but i can't figure out where

public int[] conCheck(BigInteger big)
{
    int i=0,mul=1;
    int a[]= new int[10];
 ...

26. Java_stackoverflowerror using BigInteger.     stackoverflow.com

The following code results in a stackoverflow error. How many, values of nCr, for 1<=n <=100, are greater than one-million? Please help.

import java.math.BigInteger;

public class combinatorics {

    private BigInteger ...

27. Logarithm for BigInteger    stackoverflow.com

I have a BigInteger number, for example beyond 264. Now i want to calculate the logarithm of that BigInteger number, but BigInteger.log() is not present. How do I calculate it?

28. Why is this happening in BigInteger    stackoverflow.com

BigInteger bx=new BigInteger("3806908688");

byte x[]=new byte[4];

String s=bx.toString(10);

System.out.println("string: "+s);

x=s.getBytes();

int l=0,i=0;

l |= x[i] & 0xFF;

l <<= 8;

l |= x[i+1] & 0xFF;

l <<= 8;

l |= x[i+2] & 0xFF;

l <<= 8;

l |= x[i+3] & 0xFF;

System.out.println(l);
The output ...

29. Problem with a number when storing in BigInteger and retrieving back    stackoverflow.com

BigInteger bx=new BigInteger("5888561920");

System.out.println("bx:"+bx);

byte x[]=new byte[5];

x=bx.toByteArray();

for(k=4;cnt<4;k--)
{

    cnt++;

    t[k-1]=x[k];
}

for(i=0;i<4;i++)

        System.out.print(" "+t[i]);

System.out.println("\nbig: "+toInt(t));
The output for the above code is:
bx:5888561920

 94 -4 ...

30. Efficient BigInteger in Java    stackoverflow.com

We have a set of locations within our product where BigInteger is required as the numbers can be fairly long. However, in over 90% of the cases, they are actually not ...

31. how to input a BigInteger type in java    stackoverflow.com

when I tried to get an input of type Integer, what I only needed to do was the code below.

Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
but when it comes to ...

32. Why to avoid biginteger instantiation in Java    stackoverflow.com

There is a PMD rule saying one should avoid to instantiate BigInteger or BigDecimal if there is a predefined constant.

BigInteger.ZERO

// instead of

new BigInteger(0)
Would there be any other advantage ...

33. Java BigInteger Memory Optimization    stackoverflow.com

I'm trying to find LCM of given N numbers. But this code of mine takes more than 32Mb memory. What kind of optimization can I perform here?

import java.util.Scanner ;
import java.math.BigInteger ; ...

34. Java How to invert a BigInteger?    stackoverflow.com

I need to invert a BigInteger. Let's say i have BigInteger x; and i need to calculate x.modPow(new BigInteger("-1"), p). I receive the following error: java.lang.ArithmeticException: BigInteger ...

35. BigInteger exponents - how?    coderanch.com

OK, well, here is some code: import java.math.BigInteger; public class BigIntegerX { public BigInteger pow(BigInteger mantissa, BigInteger exponent) { final BigInteger MAX_LONG = new BigInteger(Long.toString(Long.MAX_VALUE)); final BigInteger factor = new BigInteger(mantissa.toString()); BigInteger remainder = exponent.mod(MAX_LONG); for (int i = 0; i < remainder.longValue() - 1; i++) { mantissa = mantissa.multiply(factor); } exponent = exponent.subtract(remainder); while (exponent.compareTo(BigInteger.ZERO) > 0) { for (int ...

36. BigInteger back to text    coderanch.com

Hi all, I am doing some Encryption type studies and have encrypted then decrypted ok( I think). I am struggling to get what was initially a simple text file converted to byte then BigInteger, back to the same presentable text. Can someone advise a process from BigInteger to a file save state. What I have tried with all sorts of variations ...

37. Advantage of BigInteger Class    coderanch.com

The problem is that the methods in the Math class work with ints and doubles. Those types can hold only finite numbers. The BigInteger and BigDecimal classes can hold arbitrarily large numbers. Another advantage of BigDecimal is that because of the problem of representing decimal numbers in binary, doubles are not appropriate for financial programs. But BigDecimal gives you accuracy.

38. BigInteger in java    coderanch.com

39. BigInteger Class Worked on my Hex-String    coderanch.com

Hi guys, Thanks and sorry for posting one question twice because i want to change my question but it was posted so i didnot knew how i can edit. Well BigInteger worked my program though every Hex-String results as n Integer where i thought it might result as a Hex-String. Any Way i am happy that its working.... Regards.

40. BigInteger Power/Exponent BigInteger    coderanch.com

isnt the code I wrote in the post after Campbell's suggestion does exactly what his code does but in java? because the code I wrote doesnt seem to work, in Campbell's code, he never decreases the exponent... or I cant understand the code correctly how to write a java code that does the same thing as Campbell's code does? can anyone ...

41. a little BigInteger problem    coderanch.com

42. Biginteger    coderanch.com

43. BigInteger    coderanch.com

44. BigInteger and multiplying    coderanch.com

45. BigInteger    coderanch.com

46. Need help with BigInteger    coderanch.com

47. Why no toBinaryString(BigInteger b)    coderanch.com

Hi Varun, There is no toBinaryString() method, but there is a bitLength() method that tells you how many bits there are, and a testBit(int) method that tells you the state of each bit. So create a StringBuilder, store bitLength() in a variable "n", then in a for loop check each bit from n-1 to 0 and append the appropriate "1" or ...

48. Initial value for BigInteger from another BigInteger    coderanch.com

You are right, I missed the "immutable". Suppose x is an array of BigInteger. I want to compute x[i] = (x[j] + x[k]) *x[n] for various values of j, k, and n that are less than i and functions of i. The value of the reference at x[i] will change several times as I compute the value. The garbage collector will ...

49. bigInteger to float or double    coderanch.com

As soon as you turn it into a float you've lost quite a bit of accuracy already. That's because float only has 32 bits in which to store both the integer and the decimal part. double is better but still limited. The only way to maintain your accuracy is to keep using BigInteger.

50. BigInteger    coderanch.com

51. BigInteger Operations    coderanch.com

52. The bigInteger class    go4expert.com

53. BigInteger    java-forums.org

Those javadocs can be difficult to understand sometimes though. Basically, the BigInteger class was created through java to help mathematicians or anybody really, wanting to make calculations with numbers that use large amounts of digits in those numbers. Because when you initialise a variable such as a normal int or a byte or a double or float or a long etc, ...

54. My own BigInteger class. Need help.    java-forums.org

55. very new... Biginteger problems    java-forums.org

Hello I am very new to Java (this is my first java programming) and am puzzeling how to work with Big integers and i am not able to work it out My problems reduced to simple statements are the following Declaration I need to declare a new BigInteger with a value of 1 Multiply a named biginteger by 3 Add one ...

56. BigInteger value of    java-forums.org

import java.math.*; import java.util.*; public class BigInteger { public static void main (String []args) { Scanner in = new Scanner(System.in); System.out.println("How many numbers do you need to draw ?"); int k = in.nextInt(); System.out.print("What is the highest number you can draw ?"); int n = in.nextInt(); BigInteger lotteryodds = BigInteger.valueOf(1); for(int i = 1; i <=k; i++) lotteryodds = lotteryodds .multiply(BigInteger.valueOf(n ...

57. BigInteger Rational (CS106A-Stanford university)    java-forums.org

BigInteger Rational (CS106A-Stanford university) Hi Folks, This is the exercise iam trying to solve from the book "Art and science of Java": The implementation of the Rational class given in this chapter is not particularly useful in practice because it doesnt allow the numerator and denominator to exceed the size of an integer, even though larger values tend to ...

58. BigInteger class in the art & science of java    java-forums.org

Hi, I' m new to java. when I do the exercise in the book "the art and science of java", I come across a problem about BigInteger class. Here is question: The implementation of the Rational class given in this chapter is not particularly useful in practice because it doesnt allow the numerator and denominator to exceed the size of an ...

59. Does any one know how to write this e^sqrt(lognloglog(n)) ,where n is biginteger    java-forums.org

If numerical accuracy is desired (I'm assuming it is), I'd write a log function using the BigInteger and BigDecimal classes directly. You might consider talking to a mathematician. This function appears to me to be monotonic, and so a gradient descent (Newton-Raphson) approach may work and provide a solution much faster than direct computation.

60. BigInteger    java-forums.org

I have some code to add *very* large numbers. Java Code: import java.math.*; public class charles { public static void main(String[] args) { BigInteger a1 = new BigInteger("46376937677490009712648124896970078050417018260538"); BigInteger a2 = new BigInteger("74324986199524741059474233309513058123726617309629"); BigInteger a3 = new BigInteger("91942213363574161572522430563301811072406154908250"); BigInteger a4 = new BigInteger("23067588207539346171171980310421047513778063246676"); BigInteger a5 = new BigInteger("89261670696623633820136378418383684178734361726757"); BigInteger a6 = new BigInteger("28112879812849979408065481931592621691275889832738"); BigInteger a7 = new BigInteger("44274228917432520321923589422876796487670272189318"); BigInteger a8 = ...

61. Biginteger help    forums.oracle.com

62. BigInteger    forums.oracle.com

63. BigInteger    forums.oracle.com

64. BigInteger Problem    forums.oracle.com

You need to be more specific about what your problem is. Saying your gui doesn't work doesn't tell us anything useful. You shouldn't give your classes the same name as already existing classes, it just leads to confusion. There's already an Integer class in the api. If you do give them the same name, at least put it in a package ...

65. BigInteger modPow    forums.oracle.com

66. BigInteger.probablePrime() doesn't output the correct bitlength?    forums.oracle.com

From the API documentation for Random: "If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers." And: "Two Random objects created within the same millisecond will have the same sequence of random numbers." So you might consider using only one ...

67. What is BigInteger?    forums.oracle.com

I tried reading the API and googling but couldn't really find anything that tell me what it is or I'm just not understanding it. So what's the difference between an int and a BigInteger? How many bits is a BigInteger? The closest thing I could find was "a BigInteger allows you to store an arbitrary big non-decimal number" . Can anyone ...

68. BigInteger multiply limit    forums.oracle.com

YoungWinston wrote: I also noticed that your number is 4,093 digits long, which would suggest that the answer should be 4,097, so I wonder if some sort of 4K limit is being breached. But whether it's a BigInteger bug, or simply a problem with banging out that many characters to System.out in one go, I don't know. I did a little ...

69. how i can find log2 of BigInteger ?    forums.oracle.com

70. Problem with BigInteger conversions    forums.oracle.com

Hello, I have a question about the BigInteger class: How can I convert a string of decimal encoded bytes such as "12345678901234567890" to a BigInteger, then back to a string again? I want to translate it back to a string using toByteArray ( Yes I know it uses the two's compliment, I'm just not sure how to get it into a ...

71. DataType BigInteger    forums.oracle.com

72. Problem with BigInteger and short type    forums.oracle.com

I have a block of data in a byte array, and i must append at the beginning of this array those two bytes that represent the short value (this values is the amount of bytes in the block of data that is constant) i simply always have to have this zero value at the beginning, becouse the block of data must ...

73. BigInteger padding    forums.oracle.com

so say I have: BigInteger big = new BigInteger("110001", 2); I want this to be "0110001", so I want to pad this with another 0 in front?? How do I do this? I tried shifting it to the right and it becomes 11000 instead of adding 0 in front of it... how do I do this?? may seem like a stupid ...

74. BigInteger class question    forums.oracle.com

75. BigInteger heap space error in method add()    forums.oracle.com

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.math.BigInteger.add(Unknown Source) at principal.crearCompuestosOpIguales(principal.java:190) at principal.main(principal.java:124) First, I thought that the problem was the amount of memory the JVM, but after bend, the problem persists. I have seen some errors in methods of the class BigInteger, in my case it gives in the method add, but I do not know how to ...

76. BigInteger Class    forums.oracle.com

77. Extended Euclid BigInteger version    forums.oracle.com

It would also help to learn how to debug, either stepping thru your code to see where it's doing something you didn't expect, or having it simply print intermediate values to cue you in to that. In this case you would have been able to see that the (q.compareTo(BigInteger.ZERO) == 1) wasn't doing what you thought it would do, because you ...

78. BigInteger problem ? Number of possible passwords with a given set    forums.oracle.com

The code below gets the number of possible passwords created with a set of setLen and a starting password length of startNr and endNr as maximum length. Example: all number of passwords with letter from a to z and length from 1 to 8 will translate as passwdNr(27,1,8). This is computationally expensive: 2263 ms for a (70,1,9). Now the problem is ...

79. Problem with BigInteger class    forums.oracle.com

80. Ln of BigInteger    forums.oracle.com

81. Does BigInteger have a MaxValue limit?    forums.oracle.com

I was just thinking , it takes at least 4 bits to represent a decimal digit (0 to 9) So that means 1 byte = 8 bits can hold 2 decimal digits. 8 GB = 8 x 1024 MB = 8 x 1024 x 1024 B = 8388608 B = 16777216 Digits What size memory does it take to hold 16777216 ...

82. Collision in BigInteger...    forums.oracle.com

83. BigInteger Reporting incorrect values ???    forums.oracle.com

if there are 24 characters in String then conversion should be 12 byte. This suggests that you have in mind a rule like "2 characters per byte". But you first turned the characters into a BigInteger. And BigIntegers (like other sorts of number) contains one extra piece of information that we are apt to forget sometimes when we write the number ...

84. how to use biginteger    forums.oracle.com

85. Biginteger problem    forums.oracle.com

this is my current code but it only works up to 20 digits because of the limitation on long for(int test = 0; test <20; test++){ if (temp.substring(i, topN).compareToIgnoreCase("0") == 0) myInt = BigInteger.valueOf(y + y*10+0); else if (temp.substring(i, topN).compareToIgnoreCase("1") == 0) y = y * 10 + 1; else if (temp.substring(i, topN).compareToIgnoreCase("2") == 0) y = y * 10 + ...

86. Is there a class for BigInteger in c++    forums.oracle.com

87. BigInteger question    forums.oracle.com

798089 wrote: I rarely comment on here because the last time I did, a poster was nasty to me, That would be this thread, which included this comment from me: I believe he's getting frustrated because you keep asking the same thing and keep getting told the same answer. If you don't understand the answer, then it's on you to expand ...

88. BigInteger comparision is failing in 1.5    forums.oracle.com