logo

מחלקה שלמה גדולה

מחלקה Big Integer מרחיבה את Number ומטמיעה ממשק Comparable. הוא מספק אנלוגים לכל האופרטורים השלמים הפרימיטיביים של Java ולכל השיטות מחבילת java.lang.Math.

גופן גימפ

הוא מורכב משיטות או פעולות רבות עבור אריתמטיקה מודולרית, GCD ועוד רבים אחרים המתוארים להלן.

שרירי בטן() הוא מחזיר BigInteger שהערך שלו הוא הערך המוחלט של BigInteger זה.
לְהוֹסִיף() שיטה זו מחזירה BigInteger פשוט על ידי חישוב ערך 'זה + val'.
ו() שיטה זו מחזירה BigInteger על ידי חישוב הערך 'this & val'.
ולא() שיטה זו מחזירה BigInteger על ידי חישוב הערך 'this & ~val'.
bitCount() שיטה זו מחזירה את מספר הביטים בייצוג המשלים של השניים של BigInteger זה השונה מסיבית הסימן שלו.
bitLength() שיטה זו מחזירה את מספר הסיביות בייצוג המשלים המינימלי של שניים של סיביות סימן זו למעט סיביות הסימן.
clearBit() שיטה זו מחזירה BigInteger שערכו שווה ל-BigInteger זה שהביט הייעודי שלו נוקה.
בהשוואה ל() שיטה זו משווה את BigInteger זה עם BigInteger שצוין.
לחלק() שיטה זו מחזירה BigInteger על ידי חישוב הערך 'זה /~val'.
divideAndRemainder() שיטה זו מחזירה BigInteger על ידי חישוב הערך 'this & ~val' ואחריו 'this%value'.
doubleValue() שיטה זו ממירה BigInteger זה לכפול.
שווים() שיטה זו משווה את ה-BigInteger הזה עם האובייקט הנתון לצורך שוויון.
flipBit() שיטה זו מחזירה BigInteger שערכו שווה ל-BigInteger זה כשהביט המיועד מתהפך.
floatValue() שיטה זו ממירה BigInteger זה לצוף.
gcd() שיטה זו מחזירה BigInteger שהערך שלו הוא המחלק המשותף הגדול ביותר בין abs(this) ו-abs(val).
getLowestSetBit() שיטה זו מחזירה את האינדקס של הסיבית הימנית ביותר (הסדר הנמוך ביותר) ב-BigInteger זה (מספר האפס ביטים מימין לסיבית הימנית ביותר).
hashCode() שיטה זו מחזירה את קוד ה-hash עבור BigInteger זה.
intValue() שיטה זו ממירה BigInteger זה ל-int.
isProbablePrime() שיטה זו מחזירה ערך בוליאני 'true' אם ורק אם BigInteger זה הוא ראשוני אחר עבור ערכים מורכבים הוא מחזיר false.
longValue() שיטה זו מסתירה את ה-BigInteger הזה לטווח ארוך.
מקסימום() שיטה זו מחזירה את המקסימום בין BigInteger זה ל-val.
min() שיטה זו מחזירה את המינימום בין BigInteger זה ל-val.
מול() שיטה זו מחזירה ערך BigInteger עבור mod m זה.
modInverse() שיטה זו מחזירה BigInteger שהערך שלו הוא 'This inverse mod m'.
modPow() שיטה זו מחזירה BigInteger שהערך שלו הוא 'thisexponent mod m'.
לְהַכפִּיל() שיטה זו מחזירה BigInteger על ידי חישוב הערך 'זה *val'.
לִשְׁלוֹל() שיטה זו מחזירה BigInteger שהערך שלו הוא '-this'.
nextProbablePrime() שיטה זו מחזירה את המספר השלם הראשוני הבא שגדול ממספר השלם הגדול הזה.
לֹא() שיטה זו מחזירה BigInteger שהערך שלו הוא '~this'.
אוֹ() שיטה זו מחזירה BigInteger שהערך שלו הוא 'this | ואל'
pow() שיטה זו מחזירה BigInteger שהערך שלו הוא 'Thisמַעֲרִיך'.
probablePrime() שיטה זו מחזירה מספר ראשי חיובי BigInteger, עם ה-bitLength שצוין.
היתרה() שיטה זו מחזירה BigInteger שהערך שלו הוא '% val this'.
setBit() שיטה זו מחזירה BigInteger שערכו שווה ל-BigInteger זה עם ערכת הסיביות המיועדת.
shiftLeft() שיטה זו מחזירה BigInteger שהערך שלו הוא 'זה << val'.
shiftRight() שיטה זו מחזירה BigInteger שהערך שלו הוא 'זה >> val'.
סִימָן() שיטה זו מחזירה את פונקציית הסימן של BigInteger זה.
להחסיר() שיטה זו מחזירה BigInteger שהערך שלו הוא 'this - val'.
testbit() שיטה זו מחזירה ערך בוליאני 'true' אם הביט המיועד מוגדר.
toByteArray() שיטה זו מחזירה מערך בתים המכיל את ייצוג ההשלמה של שניים של BigInteger זה.
toString() שיטה זו מחזירה את ייצוג המחרוזת העשרונית של BigInteger זה.
ערך של() שיטה זו מחזירה BigInteger שהערך שלו שווה ערך לזה של ה-long שצוין.
חינם() שיטה זו מחזירה ערך BigInteger ny המחשוב את הערך 'This ^ val'.

דוגמה 1

 import java.math.BigInteger; public class BigIntegerExample1 { public static void main(String args[]) throws Exception { // Initialize result BigInteger bigInteger = new BigInteger(&apos;1&apos;); int n=4; for (int i = 2; i <=n 4 197 ; i++){ returns a biginteger by computing ?this *val ? value. } system.out.println('factorial of : '+biginteger); boolean value ?true? if and only this is prime biginteger2="new" biginteger('197'); system.out.println('isprobableprime method will return '+ biginteger2.isprobableprime(2)); the next integer that greater than biginteger. nextprimenumber="bigInteger2.nextProbablePrime();" system.out.println('prime number to '+nextprimenumber); minimum between val min="bigInteger.min(bigInteger2);" system.out.println('min '+min); maximum max="bigInteger.max(bigInteger2);" system.out.println('maximum '+max); < pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> Factorial of 4 : 24 IsProbablePrime method will return : true Prime Number next to 197 : 199 Min value : 24 Maximum value : 197 </pre> <h2>Example 2</h2> <pre> import java.math.BigInteger; public class BigIntegerExample2 { public static void main(String args[]) throws Exception { // Initialize result BigInteger bigInteger = new BigInteger(&apos;17&apos;); //returns the signum function of this BigInteger BigInteger bigInteger2 = new BigInteger(&apos;171&apos;); System.out.println(&apos;Signum value for &apos;+bigInteger2+&apos; : &apos;+ bigInteger2.signum()); //returns the next prime integer that is greater than this BigInteger. BigInteger sub=bigInteger2.subtract(bigInteger); System.out.println(bigInteger2+&apos;-&apos;+bigInteger+&apos; : &apos;+sub); // returns the quotient after dividing two bigInteger values BigInteger quotient=bigInteger2.divide(bigInteger); System.out.print(bigInteger2+&apos; / &apos;+bigInteger+&apos; : Quotient : &apos;+quotient); //returns the remainder after dividing two bigIntger values BigInteger remainder=bigInteger.remainder(bigInteger2); System.out.println(&apos; Remaider : &apos;+remainder); //returns a BigInteger whose value is ?this &lt;&lt; val? BigInteger shiftLeft=bigInteger.shiftLeft(4); System.out.println(&apos;ShiftLeft value : &apos;+shiftLeft); } } </pre> <span> Test it Now </span> <p> <strong>Output:</strong> </p> <pre> Signum value for 171 : 1 171-17 : 154 171 / 17 : Quotient : 10 Remaider : 17 ShiftLeft value : 272 </pre> <br></=n>

דוגמה 2

 import java.math.BigInteger; public class BigIntegerExample2 { public static void main(String args[]) throws Exception { // Initialize result BigInteger bigInteger = new BigInteger(&apos;17&apos;); //returns the signum function of this BigInteger BigInteger bigInteger2 = new BigInteger(&apos;171&apos;); System.out.println(&apos;Signum value for &apos;+bigInteger2+&apos; : &apos;+ bigInteger2.signum()); //returns the next prime integer that is greater than this BigInteger. BigInteger sub=bigInteger2.subtract(bigInteger); System.out.println(bigInteger2+&apos;-&apos;+bigInteger+&apos; : &apos;+sub); // returns the quotient after dividing two bigInteger values BigInteger quotient=bigInteger2.divide(bigInteger); System.out.print(bigInteger2+&apos; / &apos;+bigInteger+&apos; : Quotient : &apos;+quotient); //returns the remainder after dividing two bigIntger values BigInteger remainder=bigInteger.remainder(bigInteger2); System.out.println(&apos; Remaider : &apos;+remainder); //returns a BigInteger whose value is ?this &lt;&lt; val? BigInteger shiftLeft=bigInteger.shiftLeft(4); System.out.println(&apos;ShiftLeft value : &apos;+shiftLeft); } } 
בדוק את זה עכשיו

תְפוּקָה:

 Signum value for 171 : 1 171-17 : 154 171 / 17 : Quotient : 10 Remaider : 17 ShiftLeft value : 272