<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.compsci.ca/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.compsci.ca/index.php?action=history&amp;feed=atom&amp;title=Java_Big_Integers</id>
		<title>Java Big Integers - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.compsci.ca/index.php?action=history&amp;feed=atom&amp;title=Java_Big_Integers"/>
		<link rel="alternate" type="text/html" href="http://wiki.compsci.ca/index.php?title=Java_Big_Integers&amp;action=history"/>
		<updated>2026-04-15T04:09:02Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.16.0</generator>

	<entry>
		<id>http://wiki.compsci.ca/index.php?title=Java_Big_Integers&amp;diff=3777&amp;oldid=prev</id>
		<title>Newacct at 09:39, 22 February 2010</title>
		<link rel="alternate" type="text/html" href="http://wiki.compsci.ca/index.php?title=Java_Big_Integers&amp;diff=3777&amp;oldid=prev"/>
				<updated>2010-02-22T09:39:40Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 09:39, 22 February 2010&lt;/td&gt;
		&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 2:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 2:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;(From sun.com) &amp;quot;Immutable arbitrary-precision integers.&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;(From sun.com) &amp;quot;Immutable arbitrary-precision integers.&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;(From Answers.com) &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Immutatble&lt;/del&gt;: &amp;quot;Incapable of changing or being modified&amp;quot;, meaning the precision cannot be changed (any one else have a better.. desc?)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;(From Answers.com) &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Immutable&lt;/ins&gt;: &amp;quot;Incapable of changing or being modified&amp;quot;, meaning the precision cannot be changed (any one else have a better.. desc?)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In 'Laymans' terms, they are very large 'integer' type variables, with the capacity to hold as many digits as your RAM will fit.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;In 'Laymans' terms, they are very large 'integer' type variables, with the capacity to hold as many digits as your RAM will fit.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 61:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 61:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;bigInt1.compareTo(bigInt3);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;bigInt1.compareTo(bigInt3);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Returns: An Integer with a value &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;of -1 &lt;/del&gt;(Less Than), 0 (Equal), &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;1 &lt;/del&gt;(Greater &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Then&lt;/del&gt;), in this case, it will be &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;-1 &lt;/del&gt;since 1 is less then 3.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Returns: An Integer with a &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;negative &lt;/ins&gt;value (Less Than), 0 (Equal), &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;positive value &lt;/ins&gt;(Greater &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Than&lt;/ins&gt;), in this case, it will be &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;negative &lt;/ins&gt;since 1 is less then 3.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Whereas, bigInt1 and bigInt3 are both BigInteger's&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Whereas, bigInt1 and bigInt3 are both BigInteger's&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 72:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 72:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Whereas, bigInt1 and bigInt3 are both BigInteger's&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Whereas, bigInt1 and bigInt3 are both BigInteger's&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Youll &lt;/del&gt;notice, its just like dealing with strings (equals, compareTo)...&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;You'll &lt;/ins&gt;notice, its just like dealing with strings (equals, compareTo)...&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;As well, you can create a new BigInteger inline (outputs 8)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;As well, you can create a new BigInteger inline (outputs 8)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 84:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 84:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Can I Make An Array?==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Can I Make An Array?==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Sure, why not, arrays can be made of any object/class. Both arrays have a length of 10, both have been &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;initiallized &lt;/del&gt;to value '1'&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Sure, why not, arrays can be made of any object/class. Both arrays have a length of 10, both have been &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;initialized &lt;/ins&gt;to value '1'&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 106:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 106:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;if (new BigInteger(&amp;quot;17&amp;quot;).isProbablePrime(5) &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;== true&lt;/del&gt;){&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;if (new BigInteger(&amp;quot;17&amp;quot;).isProbablePrime(5)){&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&amp;quot;17 Is Prime!&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.println(&amp;quot;17 Is Prime!&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 113:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 113:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Bit Manipulation==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Bit Manipulation==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Im &lt;/del&gt;A 'Bit' Hungry, &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Lets &lt;/del&gt;Do Bit Manipulation!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;I'm &lt;/ins&gt;A 'Bit' Hungry, &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Let's &lt;/ins&gt;Do Bit Manipulation!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;One of the most used is XOR, in encryption methods. Eg: 65 XOR 42 = 107, and 107 XOR 42 = 65. The work behind this is, it converts the numbers to binary (1's, 0's), and compares the bits in each position, if they are different, bit = 1, if they are the same, bit = 0&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;One of the most used is XOR, in encryption methods. Eg: 65 XOR 42 = 107, and 107 XOR 42 = 65. The work behind this is, it converts the numbers to binary (1's, 0's), and compares the bits in each position, if they are different, bit = 1, if they are the same, bit = 0&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 127:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 127:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;System.out.println (&amp;quot;65 XOR 42 = &amp;quot;+new BigInteger(&amp;quot;65&amp;quot;).&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;XOR&lt;/del&gt;(new BigInteger(&amp;quot;42&amp;quot;));&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;System.out.println (&amp;quot;65 XOR 42 = &amp;quot;+new BigInteger(&amp;quot;65&amp;quot;).&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;xor&lt;/ins&gt;(new BigInteger(&amp;quot;42&amp;quot;));&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Constant Recomendations==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;==Constant Recomendations==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Seeing how it takes quite a bit of typing to make a new &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;biginteger &lt;/del&gt;every time you say want to multiply something by two... bigInt.multiply (new BigInteger(&amp;quot;2&amp;quot;);.. etc.. I &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;recomend &lt;/del&gt;making some constants at the top of your program for the most common numbers as follows:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Seeing how it takes quite a bit of typing to make a new &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;BigInteger &lt;/ins&gt;every time you say want to multiply something by two... bigInt.multiply (new BigInteger(&amp;quot;2&amp;quot;);.. etc.. I &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;recommend &lt;/ins&gt;making some constants at the top of your program for the most common numbers as follows:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 147:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 147:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;What About For Loops, Can BigIntegers Be Used?[b]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;What About For Loops, Can BigIntegers Be Used?[b]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;They can be, but &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;its unadvisable &lt;/del&gt;as it will be &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;extremly &lt;/del&gt;slow, unless incrementing by say 100 or 1000... (bellow &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;i &lt;/del&gt;used 1 for increment)...&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;They can be, but &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;it's inadvisable &lt;/ins&gt;as it will be &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;extremely &lt;/ins&gt;slow, unless incrementing by say 100 or 1000... (bellow &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;I &lt;/ins&gt;used 1 for increment)...&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Java:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;for (BigInteger bigCount = BigInteger.ZERO; bigCount.compareTo(new BigInteger (&amp;quot;99999999999999999&amp;quot;)) &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;== -1&lt;/del&gt;; bigCount = bigCount.add(BigInteger.ONE)){&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;for (BigInteger bigCount = BigInteger.ZERO; bigCount.compareTo(new BigInteger (&amp;quot;99999999999999999&amp;quot;)) &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;lt; 0&lt;/ins&gt;; bigCount = bigCount.add(BigInteger.ONE)){&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;  System.out.println (&amp;quot;Big:&amp;quot;+bigCount);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;  System.out.println (&amp;quot;Big:&amp;quot;+bigCount);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 191:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 191:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Check Out Sun's Java Docs On BigInteger. BigInteger @ Sun.com&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Check Out Sun's Java Docs On BigInteger. BigInteger @ Sun.com&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;(I Highly &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Recommmend &lt;/del&gt;You Read Through The Whole Method Summary Section)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;(I Highly &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Recommend &lt;/ins&gt;You Read Through The Whole Method Summary Section)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;As well, for the decimal equivalent, check out 'BigDecimal' BigDecimal @ Sun.com&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;As well, for the decimal equivalent, check out 'BigDecimal' BigDecimal @ Sun.com&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;BigDecimal's use the same concepts as BigInteger, so &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;i &lt;/del&gt;wont go into much detail, but if you have questions about BigDecimals, ask away.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;BigDecimal's use the same concepts as BigInteger, so &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;I &lt;/ins&gt;wont go into much detail, but if you have questions about BigDecimals, ask away.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you have any questions, comments, or things to add, feel free to leave a message, or pm me. -Kevin&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you have any questions, comments, or things to add, feel free to leave a message, or pm me. -Kevin&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Newacct</name></author>	</entry>

	<entry>
		<id>http://wiki.compsci.ca/index.php?title=Java_Big_Integers&amp;diff=3499&amp;oldid=prev</id>
		<title>TheFerret: Created page</title>
		<link rel="alternate" type="text/html" href="http://wiki.compsci.ca/index.php?title=Java_Big_Integers&amp;diff=3499&amp;oldid=prev"/>
				<updated>2008-10-11T20:26:24Z</updated>
		
		<summary type="html">&lt;p&gt;Created page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==What Are They?==&lt;br /&gt;
&lt;br /&gt;
(From sun.com) &amp;quot;Immutable arbitrary-precision integers.&amp;quot;&lt;br /&gt;
(From Answers.com) Immutatble: &amp;quot;Incapable of changing or being modified&amp;quot;, meaning the precision cannot be changed (any one else have a better.. desc?)&lt;br /&gt;
&lt;br /&gt;
In 'Laymans' terms, they are very large 'integer' type variables, with the capacity to hold as many digits as your RAM will fit.&lt;br /&gt;
&lt;br /&gt;
==When Should You Use Them?==&lt;br /&gt;
&lt;br /&gt;
They should be used whenever you need to handle very large numbers, anything larger then 'long' variables. Long's have a max a max value of 9223372036854775807. As well, BigInteger provides some useful functions for bit manipulation, GCD, random number, and primality testing and generation.&lt;br /&gt;
&lt;br /&gt;
==Do I Need To Import Anything?==&lt;br /&gt;
&lt;br /&gt;
Yes, add this import line at the top of your java file&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import java.math.*;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Declaring A BigInteger Variable (4 Examples)==&lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BigInteger bigInt0 = BigInteger.ZERO;&lt;br /&gt;
BigInteger bigInt1 = BigInteger.ONE;&lt;br /&gt;
BigInteger bigInt3 = new BigInteger (&amp;quot;3&amp;quot;);&lt;br /&gt;
BigInteger bigInt5 = BigInteger.valueOf(5);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: You cannot pass an int/long into a BigInteger directly, the easiest way to do this it to pass it as a static BigInteger using valueOf, Thank You &amp;quot;OneOffDriveByPoster&amp;quot; for that method.&lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
long num = 9876543210;&lt;br /&gt;
BigInteger bigInt123 = BigInteger.valueOf (num);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==So, How Do I Use Them?==&lt;br /&gt;
&lt;br /&gt;
Well, BigIntegers contain all the regular math functions, plus more, the main difference is, it does not use symbols such as '*', '+','=','&amp;gt;' etc. rather it uses words (multiply,add,equals,compareTo). Examples;&lt;br /&gt;
&lt;br /&gt;
To Multiply:&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bigInt1.multiply(bigInt3);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Returns: A Big Integer With Value 3 (1*3)&lt;br /&gt;
Whereas, bigInt1 and bigInt3 are both BigInteger's&lt;br /&gt;
&lt;br /&gt;
To Subtract:&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bigInt1.subtract(bigInt3);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Returns: A BigInteger with value -2 (3-1)&lt;br /&gt;
Whereas, bigInt1 and bigInt3 are both BigInteger's&lt;br /&gt;
&lt;br /&gt;
To Compare:&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bigInt1.compareTo(bigInt3);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Returns: An Integer with a value of -1 (Less Than), 0 (Equal), 1 (Greater Then), in this case, it will be -1 since 1 is less then 3.&lt;br /&gt;
Whereas, bigInt1 and bigInt3 are both BigInteger's&lt;br /&gt;
&lt;br /&gt;
To Check If Equal:&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
bigInt1.equals(bigInt3);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Returns: A boolean with a value of false since 1 != 3&lt;br /&gt;
Whereas, bigInt1 and bigInt3 are both BigInteger's&lt;br /&gt;
&lt;br /&gt;
Youll notice, its just like dealing with strings (equals, compareTo)...&lt;br /&gt;
&lt;br /&gt;
As well, you can create a new BigInteger inline (outputs 8)&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
System.out.println (&amp;quot;2**3 = &amp;quot;+new BigInteger(&amp;quot;2&amp;quot;).pow(3));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: I Used this as a special example, 'pow', raises the BigInteger '2' to the power of a regular integer '3'. Most of the math methods need BigIntegers as the initial and secondary values but this is a worthy exception to point out.&lt;br /&gt;
&lt;br /&gt;
==Can I Make An Array?==&lt;br /&gt;
&lt;br /&gt;
Sure, why not, arrays can be made of any object/class. Both arrays have a length of 10, both have been initiallized to value '1'&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//------Example One-------//&lt;br /&gt;
BigInteger i = BigInteger.ONE;&lt;br /&gt;
BigInteger [] biggg = {i,i,i,i,i,i,i,i,i,i};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
//------Example Two-------//&lt;br /&gt;
BigInteger [] biggg = new BigInteger [10];&lt;br /&gt;
for (int c = 0; c &amp;lt; biggg.length; c ++){&lt;br /&gt;
    biggg [c] = BigInteger.ONE;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Primality Testing==&lt;br /&gt;
You Mentioned Primality Testing...&lt;br /&gt;
&lt;br /&gt;
Checking if a number is prime is easy with BigIntegers,&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (new BigInteger(&amp;quot;17&amp;quot;).isProbablePrime(5) == true){&lt;br /&gt;
        System.out.println(&amp;quot;17 Is Prime!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note: The 5 is the certainty that the number is prime, this value reflects how long it takes to complete, for small primes, a value of 1-5 works, but bigger numbers may return false positives unless certainty is &amp;gt;= 5.&lt;br /&gt;
&lt;br /&gt;
==Bit Manipulation==&lt;br /&gt;
Im A 'Bit' Hungry, Lets Do Bit Manipulation!&lt;br /&gt;
&lt;br /&gt;
One of the most used is XOR, in encryption methods. Eg: 65 XOR 42 = 107, and 107 XOR 42 = 65. The work behind this is, it converts the numbers to binary (1's, 0's), and compares the bits in each position, if they are different, bit = 1, if they are the same, bit = 0&lt;br /&gt;
Kevin wrote:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
65: 1000001_______107: 1101011&lt;br /&gt;
XOR______________XOR&lt;br /&gt;
42: 0101010_______42: 0101010&lt;br /&gt;
=________________=&lt;br /&gt;
107: 1101011______65: 1000001&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
System.out.println (&amp;quot;65 XOR 42 = &amp;quot;+new BigInteger(&amp;quot;65&amp;quot;).XOR(new BigInteger(&amp;quot;42&amp;quot;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Constant Recomendations==&lt;br /&gt;
&lt;br /&gt;
Seeing how it takes quite a bit of typing to make a new biginteger every time you say want to multiply something by two... bigInt.multiply (new BigInteger(&amp;quot;2&amp;quot;);.. etc.. I recomend making some constants at the top of your program for the most common numbers as follows:&lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
BigInteger TWO = new BigInteger (&amp;quot;2&amp;quot;);&lt;br /&gt;
BigInteger THREE = new BigInteger (&amp;quot;3&amp;quot;);&lt;br /&gt;
BigInteger FIVE = new BigInteger (&amp;quot;5&amp;quot;);&lt;br /&gt;
BigInteger TEN = new BigInteger (&amp;quot;10&amp;quot;);&lt;br /&gt;
...&lt;br /&gt;
System.out.println (&amp;quot;2 * 10 = &amp;quot;+TWO.multiply(TEN));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==For Loops==&lt;br /&gt;
What About For Loops, Can BigIntegers Be Used?[b]&lt;br /&gt;
&lt;br /&gt;
They can be, but its unadvisable as it will be extremly slow, unless incrementing by say 100 or 1000... (bellow i used 1 for increment)...&lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
for (BigInteger bigCount = BigInteger.ZERO; bigCount.compareTo(new BigInteger (&amp;quot;99999999999999999&amp;quot;)) == -1; bigCount = bigCount.add(BigInteger.ONE)){&lt;br /&gt;
     System.out.println (&amp;quot;Big:&amp;quot;+bigCount);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Example Program==&lt;br /&gt;
Can I See A Full Program Using BigIntegers?&lt;br /&gt;
&lt;br /&gt;
Sure...A Method To Evaluate Factorials! I used BigInteger for the result, because even 25! uses 26 digits, far larger then the max 'long' capacity.&lt;br /&gt;
&lt;br /&gt;
Java:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public static BigInteger factorial(int n){&lt;br /&gt;
    /* n must be &amp;gt;= 0, 0! = 1, eg: n=5 returns (5x4x3x2x1) */&lt;br /&gt;
&lt;br /&gt;
    /* Holds the value of the factorial, in BigInteger form */&lt;br /&gt;
    BigInteger product = BigInteger.ONE;&lt;br /&gt;
       &lt;br /&gt;
    /* Inform User that n was erroneous parameter */&lt;br /&gt;
    if (n &amp;lt; 0){&lt;br /&gt;
        System.out.println (&amp;quot;Factorial Error! n = &amp;quot;+n);&lt;br /&gt;
        return new BigInteger (&amp;quot;-1&amp;quot;);&lt;br /&gt;
    }   &lt;br /&gt;
       &lt;br /&gt;
    /* Chain Multiply from 'n' to '1' */&lt;br /&gt;
    for (int c = n; c &amp;gt; 0; c --){&lt;br /&gt;
        product = product.multiply(BigInteger.valueOf(c));&lt;br /&gt;
    }&lt;br /&gt;
                       &lt;br /&gt;
    System.out.println (&amp;quot;Factorial &amp;quot;+n+&amp;quot;! = &amp;quot;+product);&lt;br /&gt;
       &lt;br /&gt;
    /* Return a BigInteger with the product from n! */&lt;br /&gt;
    return product;&lt;br /&gt;
}// end factorial&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==For More Information==&lt;br /&gt;
For More Information &amp;amp; Complete Method List&lt;br /&gt;
&lt;br /&gt;
Check Out Sun's Java Docs On BigInteger. BigInteger @ Sun.com&lt;br /&gt;
(I Highly Recommmend You Read Through The Whole Method Summary Section)&lt;br /&gt;
&lt;br /&gt;
As well, for the decimal equivalent, check out 'BigDecimal' BigDecimal @ Sun.com&lt;br /&gt;
BigDecimal's use the same concepts as BigInteger, so i wont go into much detail, but if you have questions about BigDecimals, ask away.&lt;br /&gt;
&lt;br /&gt;
If you have any questions, comments, or things to add, feel free to leave a message, or pm me. -Kevin&lt;br /&gt;
&lt;br /&gt;
==Credits==&lt;br /&gt;
&lt;br /&gt;
Author: [[the_short1]]&lt;br /&gt;
&lt;br /&gt;
Added to Wiki by: [[TheFerret]]&lt;/div&gt;</summary>
		<author><name>TheFerret</name></author>	</entry>

	</feed>