Think of that, in the C language learning, we are often instilled in the scope of int can not exceed 2^32 if your operating system is 64-bit can also go to 2^64, and long is fixed 2^32, if you want to use a larger number, you should use a double, such as floating-point expression, Although the length of the double is your operating system bit long, but the large data will still lose precision, so the C language even there are some big data but can not lose the accuracy of the array problem, remember when I have done, using a loop structure to a long data string, such as 64 1, Constantly on the 10, and then to achieve subtraction, very complex, and after learning the assembly language, can only use displacement to achieve subtraction time, the program is written by the elder elders.
Of course, usually do not have to consider so much, because we deal with the data is rarely more than the 2^32 of int, after all, we are not reading math department, the length of int is enough, we deal with the data in fact many times more than 255 is good. However, if you let me work with a very long data, I can still easily solve it in Java, after all, Java has already encapsulated the processing of big data in BigInteger.
The following is the basic use of BigInteger, that is, the construction method and the four mixed operation:
public static void Bigintegertest () {BigInteger num1 = new BigInteger (" 1111111111111111111111111111111111111111111111111111111111111 "); BigInteger num2 = new BigInteger ("11111111111111111111111111111111111111111111111111111111111111"); System.out.println ("Num1 plus num2 Result:" + num1.add (num2)); System.out.println ("Num1 minus num2 result is:" + num1.subtract (num2)); System.out.println ("Num1 multiplied by the num2 result is:" + num1.multiply (num2)); System.out.println ("Num1 divided by the quotient of num2:" + num1.divide (num2)); The remainder of the System.out.println ("Num1 divided by num2 is:" + num1.mod (num2)); The result of System.out.println ("NUM1 to 2 (i.e. whether the NUM1 is even even) is:" + num1.mod (New BigInteger ("2"));}
Yes, remember to use import java.math.* in the head, because BigInteger to use this class
Here is the result of the operation after the above method is called:
Test of ======BIGINTEGER data structure begins ======
The result of NUM1 plus num2 is: 12222222222222222222222222222222222222222222222222222222222222
The result of Num1 minus num2 is:-10000000000000000000000000000000000000000000000000000000000000
The result of multiplying num1 by num2 is: 1234567901234567901234567901234567901234567901234567901234567765432098765432098765432098765432098765432098 7654320987654321
Num1 divided by the quotient of num2:0
The remainder of num1 divided by num2 is: 1111111111111111111111111111111111111111111111111111111111111
The result of NUM1 to 2 (i.e. whether NUM1 is even) is: 1
Test end of ======BIGINTEGER data structure ======
1, subtraction to use the Add,subtract,multiply,divide,mod method, the same as the usual program operators, the so-called except only to find two of the quotient
2. All of the above methods must be BigInteger type.
3. The BigInteger method must be a string, not a number, such as New BigInteger ( 1111111111111111111111111111111111111111111111111111111111111); it is wrong, because in Java, even no program can pass such a long number, so long as the parameter is used.
"Java" Since the BigInteger, I don't have to worry about how much data to deal with.