Java-math-biginteger

提供:Dev Guides
移動先:案内検索

Java.math.BigIntegerクラス

前書き

*java.math.BigInteger* クラスは、Javaのすべてのプリミティブ整数演算子に類似した操作と、java.lang.Mathのすべての関連メソッドを提供します。

また、モジュラー演算、GCD計算、素数テスト、素数生成、ビット操作、およびその他のいくつかのその他の操作の操作も提供します。 すべての操作は、BigIntegerが2の補数表記で表されているかのように動作します。

算術演算とビット単位の論理演算のセマンティクスは、それぞれJavaの整数演算演算子とJavaのビット単位整数演算子のセマンティクスに似ています。 シフト操作のセマンティクスは、Javaのシフト演算子のセマンティクスを拡張して、負のシフト距離を可能にします。

比較演算は、符号付き整数の比較を実行します。 剰余を計算し、べき乗を実行し、乗法的逆数を計算するためのモジュラー算術演算が提供されています。 ビット演算は、オペランドの2の補数表現の1ビットで動作します。

このクラスのすべてのメソッドとコンストラクターは、入力パラメーターにnullオブジェクト参照が渡されるとNullPointerExceptionをスローします。

クラス宣言

以下は java.math.BigInteger クラスの宣言です-

public class BigInteger
   extends Number
      implements Comparable<BigInteger>

フィールド

以下は java.math.BigInteger クラスのフィールドです-

  • static BigInteger ONE -BigInteger定数1。
  • static BigInteger TEN -BigIntegerの定数10。
  • static BigInteger ZERO -BigInteger定数ゼロ。

クラスコンストラクター

Sr.No. Constructor & Description
1

BigInteger(byte[] val)

このコンストラクターは、BigIntegerの2の補数バイナリ表現を含むバイト配列をBigIntegerに変換するために使用されます。

2

BigInteger(int signum, byte[] magnitude)

このコンストラクターは、BigIntegerの符号強度表現をBigIntegerに変換するために使用されます。

3

BigInteger(int bitLength, int certainty, Random rnd)

このコンストラクターは、指定されたbitLengthで、おそらく素数であるランダムに生成された正のBigIntegerを構築するために使用されます。

4

BigInteger(int numBits, Random rnd)

このコンストラクターは、0〜(2 ^ numBits ^-1)の範囲に均一に分布する、ランダムに生成されたBigIntegerを構築するために使用されます。

5

BigInteger(String val)

このコンストラクターは、BigIntegerの10進ストリング表現をBigIntegerに変換するために使用されます。

6

BigInteger(String val, int radix)

このコンストラクターは、指定された基数のBigIntegerのString表現をBigIntegerに変換するために使用されます。

クラスメソッド

Sr.No. Method & Description
1

BigInteger abs()

このメソッドは、値がこのBigIntegerの絶対値であるBigIntegerを返します。

2

BigInteger add(BigInteger val)

このメソッドは、値が(this + val)であるBigIntegerを返します。

3

BigInteger and(BigInteger val)

このメソッドは、値が(this&val)であるBigIntegerを返します。

4

BigInteger andNot(BigInteger val)

このメソッドは、値が(this&〜val)であるBigIntegerを返します。

5

int bitCount()

このメソッドは、このBigIntegerの2の補数表現の符号ビットと異なるビット数を返します。

6

int bitLength()

このメソッドは、符号ビットを除いて、このBigIntegerの最小の2の補数表現のビット数を返します。

7

BigInteger clearBit(int n)

このメソッドは、指定されたビットがクリアされたこのBigIntegerと値が等しいBigIntegerを返します。

8

int compareTo(BigInteger val)

このメソッドは、このBigIntegerを指定されたBigIntegerと比較します。

9

BigInteger divide(BigInteger val)

このメソッドは、値が(this/val)であるBigIntegerを返します。

10

BigInteger[ divideAndRemainder(BigInteger val)]

このメソッドは、(this/val)に続いて(this%val)を含む2つのBigIntegerの配列を返します。

11

double doubleValue()

このメソッドは、このBigIntegerをdoubleに変換します。

12

boolean equals(Object x)

このメソッドは、このBigIntegerが指定されたオブジェクトと等しいかどうかを比較します。

13

BigInteger flipBit(int n)

このメソッドは、指定されたビットが反転されたこのBigIntegerと同等の値を持つBigIntegerを返します。

14

float floatValue()

このメソッドは、このBigIntegerをfloatに変換します。

15

BigInteger gcd(BigInteger val)

このメソッドは、値がabs(this)とabs(val)の最大公約数であるBigIntegerを返します。

16

int getLowestSetBit()

このメソッドは、このBigIntegerの右端(最下位)の1ビット(右端の1ビットの右側のゼロビットの数)のインデックスを返します。

17

int hashCode()

このメソッドは、このBigIntegerのハッシュコードを返します。

18

int intValue()

このメソッドは、このBigIntegerをintに変換します。

19

boolean isProbablePrime(int certainty)

このメソッドは、このBigIntegerが素数である可能性が高い場合はtrueを返し、間違いなく複合である場合はfalseを返します。

20

long longValue()

このメソッドは、このBigIntegerをlongに変換します。

21

BigInteger max(BigInteger val)

このメソッドは、このBigIntegerとvalの最大値を返します。

22

BigInteger min(BigInteger val)

このメソッドは、このBigIntegerとvalの最小値を返します。

23

BigInteger mod(BigInteger m)

このメソッドは、値が(this mod m)であるBigIntegerを返します。

24

BigInteger modInverse(BigInteger m)

このメソッドは、値が(this ^ -1 ^ mod m)であるBigIntegerを返します。

25

BigInteger modPow(BigInteger exponent, BigInteger m)

このメソッドは、値が(this ^ exponent ^ mod m)であるBigIntegerを返します。

26

BigInteger multiply(BigInteger val)

このメソッドは、値が(this * val)であるBigIntegerを返します。

27

BigInteger negate()

このメソッドは、値が(-this)のBigIntegerを返します。

28

BigInteger nextProbablePrime()

このメソッドは、おそらく素数であるこのBigIntegerよりも大きい最初の整数を返します。

29

BigInteger not()

このメソッドは、値が(〜this)のBigIntegerを返します。

30

BigInteger or(BigInteger val)

このメソッドは、値が(this

val)であるBigIntegerを返します。 31

BigInteger pow(int exponent)

このメソッドは、値が(this ^ exponent ^)であるBigIntegerを返します。

32

static BigInteger probablePrime(int bitLength, Random rnd)

このメソッドは、指定されたbitLengthを持つ、おそらく素数である正のBigIntegerを返します。

33

BigInteger remainder(BigInteger val)

このメソッドは、値が(this%val)であるBigIntegerを返します。

34

BigInteger setBit(int n)

このメソッドは、指定されたビットが設定されたこのBigIntegerと同等の値を持つBigIntegerを返します。

35

BigInteger shiftLeft(int n)

このメソッドは、値が(this << n)であるBigIntegerを返します。

36

BigInteger shiftRight(int n)

このメソッドは、値が(this >> n)であるBigIntegerを返します。

37

int signum()

このメソッドは、このBigIntegerのsignum関数を返します。

38

BigInteger subtract(BigInteger val)

このメソッドは、値が(this-val)であるBigIntegerを返します。

39

boolean testBit(int n)

このメソッドは、指定されたビットが設定されている場合にのみtrueを返します。

40

byte[ toByteArray()]

このメソッドは、このBigIntegerの2の補数表現を含むバイト配列を返します。

41

String toString()

このメソッドは、このBigIntegerの10進文字列表現を返します。

42

String toString(int radix)

このメソッドは、指定された基数でこのBigIntegerの文字列表現を返します。

43

static BigInteger valueOf(long val)

このメソッドは、指定されたlongの値と等しいBigIntegerを返します。

44