Class EInteger
- java.lang.Object
-
- com.upokecenter.numbers.EInteger
-
- All Implemented Interfaces:
java.lang.Comparable<EInteger>
public final class EInteger extends java.lang.Object implements java.lang.Comparable<EInteger>
Represents an arbitrary-precision integer. (The "E" stands for "extended", and has this prefix to group it with the other classes common to this library, particularly EDecimal, EFloat, and ERational.)Instances of this class are immutable, so they are inherently safe for use by multiple threads. Multiple instances of this object with the same value are interchangeable, but they should be compared using the "Equals" method rather than the "==" operator.
Security note
It is not recommended to implement security-sensitive algorithms using the methods in this class, for several reasons:
EIntegerobjects are immutable, so they can't be modified, and the memory they occupy is not guaranteed to be cleared in a timely fashion due to garbage collection. This is relevant for applications that use many-bit-long numbers as secret parameters.- The methods in this class (especially those that involve arithmetic) are not guaranteed to be "constant-time" (non-data-dependent) for all relevant inputs. Certain attacks that involve encrypted communications have exploited the timing and other aspects of such communications to derive keying material or cleartext indirectly.
Applications should instead use dedicated security libraries to handle big numbers in security-sensitive algorithms.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description EIntegerAbs()Returns the absolute value of this object's value.EIntegerAdd(int intValue)Adds this arbitrary-precision integer and a 32-bit signed integer and returns the result.EIntegerAdd(long longValue)Adds this arbitrary-precision integer and a 64-bit signed integer and returns the result.EIntegerAdd(EInteger bigintAugend)Adds this arbitrary-precision integer and another arbitrary-precision integer and returns the result.EIntegerAnd(EInteger other)Does an AND operation between this arbitrary-precision integer and another one.EIntegerAndNot(EInteger second)Does an AND NOT operation between this arbitrary-precision integer and another one.intAsInt32Checked()Deprecated.Renamed to ToInt32Checked.intAsInt32Unchecked()Deprecated.Renamed to ToInt32Unchecked.longAsInt64Checked()Deprecated.Renamed to ToInt64Checked.longAsInt64Unchecked()Deprecated.Renamed to ToInt64Unchecked.booleanCanFitInInt32()Returns whether this object's value can fit in a 32-bit signed integer.booleanCanFitInInt64()Returns whether this object's value can fit in a 64-bit signed integer.intcompareTo(int intValue)Compares an arbitrary-precision integer with this instance.intcompareTo(long longValue)Compares an arbitrary-precision integer with this instance.intcompareTo(EInteger other)Compares an arbitrary-precision integer with this instance.EIntegerDecrement()Returns one subtracted from this arbitrary-precision integer.EIntegerDivide(int intValue)Divides this arbitrary-precision integer by a 32-bit signed integer and returns the result.EIntegerDivide(long longValue)Divides this arbitrary-precision integer by a 64-bit signed integer and returns the result.EIntegerDivide(EInteger bigintDivisor)Divides this arbitrary-precision integer by another arbitrary-precision integer and returns the result.EInteger[]DivRem(int intDivisor)Divides this arbitrary-precision integer by a 32-bit signed integer and returns a two-item array containing the result of the division and the remainder, in that order.EInteger[]DivRem(long intDivisor)Divides this arbitrary-precision integer by a 64-bit signed integer and returns a two-item array containing the result of the division and the remainder, in that order.EInteger[]DivRem(EInteger divisor)Divides this arbitrary-precision integer by another arbitrary-precision integer and returns a two-item array containing the result of the division and the remainder, in that order.booleanequals(java.lang.Object obj)Determines whether this object and another object are equal and have the same type.EIntegerEqv(EInteger second)Does an XOR NOT operation (or equivalence operation, EQV operation, or exclusive-OR NOT operation) between this arbitrary-precision integer and another one.static EIntegerFromBoolean(boolean boolValue)Converts a boolean value (true or false) to an arbitrary-precision integer.static EIntegerFromByte(byte inputByte)Converts a byte (from 0 to 255) to an arbitrary-precision integer.static EIntegerFromBytes(byte[] bytes, boolean littleEndian)Initializes an arbitrary-precision integer from an array of bytes.static EIntegerFromBytes(byte[] bytes, int offset, int length, boolean littleEndian)Initializes an arbitrary-precision integer from a portion of an array of bytes.static EIntegerFromInt16(short inputInt16)Converts a 16-bit signed integer to an arbitrary-precision integer.static EIntegerFromInt32(int intValue)Converts a 32-bit signed integer to an arbitrary-precision integer.static EIntegerFromInt64(long longerValue)Converts a 64-bit signed integer to an arbitrary-precision integer.static EIntegerFromInt64AsUnsigned(long longerValue)Converts an unsigned integer expressed as a 64-bit signed integer to an arbitrary-precision integer.static EIntegerFromRadixString(byte[] bytes, int radix)Converts a sequence of bytes (interpreted as text) to an arbitrary-precision integer in a given radix.static EIntegerFromRadixString(char[] cs, int radix)Converts a sequence ofchars to an arbitrary-precision integer in a given radix.static EIntegerFromRadixString(java.lang.String str, int radix)Converts a string to an arbitrary-precision integer in a given radix.static EIntegerFromRadixSubstring(byte[] bytes, int radix, int index, int endIndex)Converts a portion of a sequence of bytes (interpreted as text) to an arbitrary-precision integer in a given radix.static EIntegerFromRadixSubstring(char[] cs, int radix, int index, int endIndex)Converts a portion of a sequence ofchars to an arbitrary-precision integer in a given radix.static EIntegerFromRadixSubstring(java.lang.String str, int radix, int index, int endIndex)Converts a portion of a string to an arbitrary-precision integer in a given radix.static EIntegerFromString(byte[] bytes)Converts a sequence of bytes (interpreted as text) to an arbitrary-precision integer.static EIntegerFromString(char[] cs)Converts a sequence ofchars to an arbitrary-precision integer.static EIntegerFromString(java.lang.String str)Converts a string to an arbitrary-precision integer.static EIntegerFromSubstring(byte[] bytes, int index, int endIndex)Converts a portion of a sequence of bytes (interpreted as text) to an arbitrary-precision integer.static EIntegerFromSubstring(char[] cs, int index, int endIndex)Converts a portion of a sequence ofchars to an arbitrary-precision integer.static EIntegerFromSubstring(java.lang.String str, int index, int endIndex)Converts a portion of a string to an arbitrary-precision integer.EIntegerGcd(EInteger bigintSecond)Returns the greatest common divisor of this integer and the given integer.intGetDigitCount()Deprecated.This method may overflow.EIntegerGetDigitCountAsEInteger()Returns the number of decimal digits used by this integer, in the form of an arbitrary-precision integer.longGetDigitCountAsInt64()Returns the number of decimal digits used by this integer, in the form of a 64-bit signed integer.intGetLowBit()Deprecated.This method may overflow.EIntegerGetLowBitAsEInteger()Gets the bit position of the lowest set bit in this number's absolute value, in the form of an arbitrary-precision integer.longGetLowBitAsInt64()Gets the bit position of the lowest set bit in this number's absolute value, in the form of a 64-bit signed integer.static EIntegergetOne()Gets the number 1 as an arbitrary-precision integer.booleanGetSignedBit(int index)Returns whether a bit is set in the two's-complement form (see"Forms of numbers") of this object's value.booleanGetSignedBit(EInteger bigIndex)Returns whether a bit is set in the two's-complement form (see"Forms of numbers") of this object's value.intGetSignedBitLength()Deprecated.This method may overflow.EIntegerGetSignedBitLengthAsEInteger()Finds the minimum number of bits needed to represent this object's value, except for its sign, and returns that number of bits as an arbitrary-precision integer.longGetSignedBitLengthAsInt64()Finds the minimum number of bits needed to represent this object's value, except for its sign, and returns that number of bits as a 64-bit signed integer.static EIntegergetTen()Gets the number 10 as an arbitrary-precision integer.booleanGetUnsignedBit(int index)Returns whether a bit is set in this number's absolute value.booleanGetUnsignedBit(EInteger bigIndex)Returns whether a bit is set in this number's absolute value.intGetUnsignedBitLength()Deprecated.This method may overflow.EIntegerGetUnsignedBitLengthAsEInteger()Finds the minimum number of bits needed to represent this number's absolute value, and returns that number of bits as an arbitrary-precision integer.longGetUnsignedBitLengthAsInt64()Finds the minimum number of bits needed to represent this number's absolute value, and returns that number of bits as a 64-bit signed integer.static EIntegergetZero()Gets the number zero as an arbitrary-precision integer.inthashCode()Returns the hash code for this instance.EIntegerImp(EInteger second)Does an OR NOT operation between this arbitrary-precision integer and another one.EIntegerIncrement()Returns one added to this arbitrary-precision integer.booleanisEven()Gets a value indicating whether this value is even.booleanisPowerOfTwo()Gets a value indicating whether this object's value is a power of two, and greater than 0.booleanisZero()Gets a value indicating whether this value is 0.EIntegerLowBits(int bitCount)Extracts the lowest bits of this integer.EIntegerLowBits(long longBitCount)Extracts the lowest bits of this integer.EIntegerLowBits(EInteger bigBitCount)Extracts the lowest bits of this integer.static EIntegerMax(EInteger first, EInteger second)Returns the greater of two arbitrary-precision integers.static EIntegerMaxMagnitude(EInteger first, EInteger second)Of two arbitrary-precision integers, returns the one with the greater absolute value.static EIntegerMin(EInteger first, EInteger second)Returns the smaller of two arbitrary-precision integers.static EIntegerMinMagnitude(EInteger first, EInteger second)Of two arbitrary-precision integers, returns the one with the smaller absolute value.EIntegerMod(int smallDivisor)Finds the modulus remainder that results when this instance is divided by the value of another integer.EIntegerMod(EInteger divisor)Finds the modulus remainder that results when this instance is divided by the value of an arbitrary-precision integer.EIntegerModPow(EInteger pow, EInteger mod)Calculates the remainder when this arbitrary-precision integer raised to a certain power is divided by another arbitrary-precision integer.EIntegerMultiply(int intValue)Multiplies this arbitrary-precision integer by a 32-bit signed integer and returns the result.EIntegerMultiply(long longValue)Multiplies this arbitrary-precision integer by a 64-bit signed integer and returns the result.EIntegerMultiply(EInteger bigintMult)Multiplies this arbitrary-precision integer by another arbitrary-precision integer and returns the result.EIntegerNegate()Gets the value of this object with the sign reversed.EIntegerNot()Returns an arbitrary-precision integer with every bit flipped from this one (also called an inversion or NOT operation).EIntegerOr(EInteger second)Does an OR operation between this arbitrary-precision integer and another one.EIntegerOrNot(EInteger second)Does an OR NOT operation between this arbitrary-precision integer and another one.EIntegerPow(int powerSmall)Raises an arbitrary-precision integer to a power.EIntegerPow(long longPower)Raises an arbitrary-precision integer to a power.EIntegerPow(EInteger bigPower)Raises an arbitrary-precision integer to a power.EIntegerPowBigIntVar(EInteger power)Deprecated.Use Pow instead.EIntegerRemainder(int intValue)Returns the remainder that would result when this arbitrary-precision integer is divided by a 32-bit signed integer.EIntegerRemainder(long longValue)Returns the remainder that would result when this arbitrary-precision integer is divided by a 64-bit signed integer.EIntegerRemainder(EInteger divisor)Returns the remainder that would result when this arbitrary-precision integer is divided by another arbitrary-precision integer.EIntegerRoot(int root)Finds the nth root of this instance's value, rounded down.EIntegerRoot(EInteger root)Finds the nth root of this instance's value, rounded down.EInteger[]RootRem(int root)Calculates the nth root and the remainder.EInteger[]RootRem(EInteger root)Calculates the nth root and the remainder.EIntegerShiftLeft(int numberBits)Returns an arbitrary-precision integer with the bits shifted to the left by a number of bits.EIntegerShiftLeft(EInteger eshift)Returns an arbitrary-precision integer with the bits shifted to the left by a number of bits given as an arbitrary-precision integer.EIntegerShiftRight(int numberBits)Returns an arbitrary-precision integer with the bits shifted to the right.EIntegerShiftRight(EInteger eshift)Returns an arbitrary-precision integer with the bits shifted to the right.intsignum()Gets the sign of this object's value.EIntegerSqrt()Finds the square root of this instance's value, rounded down.EInteger[]SqrtRem()Calculates the square root and the remainder.EIntegerSubtract(int intValue)Subtracts a 32-bit signed integer from this arbitrary-precision integer and returns the result.EIntegerSubtract(long longValue)Subtracts a 64-bit signed integer from this arbitrary-precision integer and returns the result.EIntegerSubtract(EInteger subtrahend)Subtracts an arbitrary-precision integer from this arbitrary-precision integer and returns the result.byteToByteChecked()Converts this number's value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255).byte[]ToBytes(boolean littleEndian)Returns a byte array of this integer's value.byteToByteUnchecked()Converts this number to a byte (from 0 to 255), returning the least-significant bits of this number's two's-complement form.shortToInt16Checked()Converts this number's value to a 16-bit signed integer if it can fit in a 16-bit signed integer.shortToInt16Unchecked()Converts this number to a 16-bit signed integer, returning the least-significant bits of this number's two's-complement form.intToInt32Checked()Converts this object's value to a 32-bit signed integer, throwing an exception if it can't fit.intToInt32Unchecked()Converts this object's value to a 32-bit signed integer.longToInt64Checked()Converts this object's value to a 64-bit signed integer, throwing an exception if it can't fit.longToInt64Unchecked()Converts this object's value to a 64-bit signed integer.java.lang.StringToRadixString(int radix)Generates a string representing the value of this object, in the given radix.java.lang.StringtoString()Converts this object to a text string in base 10.EIntegerXor(EInteger other)Does an exclusive OR (XOR) operation between this arbitrary-precision integer and another one.EIntegerXorNot(EInteger second)Does an XOR NOT operation (or equivalence operation, EQV operation, or exclusive-OR NOT operation) between this arbitrary-precision integer and another one.
-
-
-
Method Detail
-
getOne
public static EInteger getOne()
Gets the number 1 as an arbitrary-precision integer.- Returns:
- The number 1 as an arbitrary-precision integer.
-
getTen
public static EInteger getTen()
Gets the number 10 as an arbitrary-precision integer.- Returns:
- The number 10 as an arbitrary-precision integer.
-
getZero
public static EInteger getZero()
Gets the number zero as an arbitrary-precision integer.- Returns:
- The number zero as an arbitrary-precision integer.
-
isEven
public final boolean isEven()
Gets a value indicating whether this value is even.- Returns:
trueif this value is even; otherwise,false.
-
isPowerOfTwo
public final boolean isPowerOfTwo()
Gets a value indicating whether this object's value is a power of two, and greater than 0.- Returns:
trueif this object's value is a power of two, and greater than 0; otherwise,false.
-
isZero
public final boolean isZero()
Gets a value indicating whether this value is 0.- Returns:
trueif this value is 0; otherwise,false.
-
signum
public final int signum()
Gets the sign of this object's value.- Returns:
- The sign of this object's value.
-
FromBytes
public static EInteger FromBytes(byte[] bytes, boolean littleEndian)
Initializes an arbitrary-precision integer from an array of bytes.- Parameters:
bytes- A byte array consisting of the two's-complement form (see"Forms of numbers") of the arbitrary-precision integer to create. The byte array is encoded using the rules given in the FromBytes(bytes, offset, length, littleEndian) overload.littleEndian- If true, the byte order is little-endian, or least-significant-byte first. If false, the byte order is big-endian, or most-significant-byte first.- Returns:
- An arbitrary-precision integer. Returns 0 if the byte array's length is 0.
- Throws:
java.lang.NullPointerException- The parameterbytesis null.
-
FromBytes
public static EInteger FromBytes(byte[] bytes, int offset, int length, boolean littleEndian)
Initializes an arbitrary-precision integer from a portion of an array of bytes. The portion of the byte array is encoded using the following rules:- Positive numbers have the first byte's highest bit cleared, and negative numbers have the bit set.
- The last
byte contains the lowest 8-bits, the next-to-last contains the next
lowest 8 bits, and so on. For example, the number 300 can be encoded
as
0x01, 0x2Cand 200 as0x00, 0xC8. (Note that the second example contains a set high bit in0xC8, so an additional 0 is added at the start to ensure it's interpreted as positive.) - To encode negative numbers, take the absolute
value of the number, subtract by 1, encode the number into bytes,
and toggle each bit of each byte. Any further bits that appear
beyond the most significant bit of the number will be all ones. For
example, the number -450 can be encoded as
0xfe, 0x70and -52869 as0xff, 0x31, 0x7B. (Note that the second example contains a cleared high bit in0x31, 0x7B, so an additional 0xff is added at the start to ensure it's interpreted as negative.)
For little-endian, the byte order is reversed from the byte order just discussed.
- Parameters:
bytes- A byte array consisting of the two's-complement form (see"Forms of numbers") of the arbitrary-precision integer to create. The byte array is encoded using the rules given in the FromBytes(bytes, offset, length, littleEndian) overload.offset- An index starting at 0 showing where the desired portion ofbytesbegins.length- The length, in bytes, of the desired portion ofbytes(but not more thanbytes's length).littleEndian- If true, the byte order is little-endian, or least-significant-byte first. If false, the byte order is big-endian, or most-significant-byte first.- Returns:
- An arbitrary-precision integer. Returns 0 if the byte array's length is 0.
- Throws:
java.lang.NullPointerException- The parameterbytesis null.java.lang.IllegalArgumentException- Eitheroffsetorlengthis less than 0 or greater thanbytes's length, orbytes's length minusoffsetis less thanlength.
-
FromBoolean
public static EInteger FromBoolean(boolean boolValue)
Converts a boolean value (true or false) to an arbitrary-precision integer.- Parameters:
boolValue- Either true or false.- Returns:
- The number 1 if
boolValueis true; otherwise, 0.
-
FromInt32
public static EInteger FromInt32(int intValue)
Converts a 32-bit signed integer to an arbitrary-precision integer.- Parameters:
intValue- The parameterintValueis a 32-bit signed integer.- Returns:
- An arbitrary-precision integer with the same value as the 64-bit number.
-
FromInt64AsUnsigned
public static EInteger FromInt64AsUnsigned(long longerValue)
Converts an unsigned integer expressed as a 64-bit signed integer to an arbitrary-precision integer.- Parameters:
longerValue- A 64-bit signed integer. If this value is 0 or greater, the return value will represent it. If this value is less than 0, the return value will store 2^64 plus this value instead.- Returns:
- An arbitrary-precision integer. If
longerValueis 0 or greater, the return value will represent it. IflongerValueis less than 0, the return value will store 2^64 plus this value instead.
-
FromInt64
public static EInteger FromInt64(long longerValue)
Converts a 64-bit signed integer to an arbitrary-precision integer.- Parameters:
longerValue- The parameterlongerValueis a 64-bit signed integer.- Returns:
- An arbitrary-precision integer with the same value as the 64-bit number.
-
FromRadixString
public static EInteger FromRadixString(java.lang.String str, int radix)
Converts a string to an arbitrary-precision integer in a given radix.- Parameters:
str- A string described by the FromRadixSubstring method.radix- A base from 2 to 36. Depending on the radix, the string can use the basic digits 0 to 9 (U+0030 to U+0039) and then the basic upper-case letters A to Z (U+0041 to U+005A). For example, 0-9 in radix 10, and 0-9, then A-F in radix 16. Where a basic upper-case letter A to Z is allowed in the string, the corresponding basic lower-case letter (U+0061 to U+007a) is allowed instead.- Returns:
- An arbitrary-precision integer with the same value as the given string.
- Throws:
java.lang.NullPointerException- The parameterstris null.java.lang.NumberFormatException- The string is empty or in an invalid format.
-
FromRadixSubstring
public static EInteger FromRadixSubstring(java.lang.String str, int radix, int index, int endIndex)
Converts a portion of a string to an arbitrary-precision integer in a given radix.- Parameters:
str- A text string. The desired portion of the string must contain only characters allowed by the given radix, except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The desired portion is not allowed to contain white space characters, including spaces. The desired portion may start with any number of zeros.radix- A base from 2 to 36. Depending on the radix, the string can use the basic digits 0 to 9 (U+0030 to U+0039) and then the basic upper-case letters A to Z (U+0041 to U+005A). For example, 0-9 in radix 10, and 0-9, then A-F in radix 16. Where a basic upper-case letter A to Z is allowed in the string, the corresponding basic lower-case letter (U+0061 to U+007a) is allowed instead.index- The index of the string that starts the string portion.endIndex- The index of the string that ends the string portion. The length will be index + endIndex - 1.- Returns:
- An arbitrary-precision integer with the same value as given in the string portion.
- Throws:
java.lang.NullPointerException- The parameterstris null.java.lang.NumberFormatException- The string portion is empty or in an invalid format.
-
FromSubstring
public static EInteger FromSubstring(char[] cs, int index, int endIndex)
Converts a portion of a sequence ofchars to an arbitrary-precision integer.- Parameters:
cs- A sequence ofchars, the desired portion of which describes an integer in base-10 (decimal) form. The desired portion of the sequence ofchars must contain only basic digits 0 to 9 (U+0030 to U+0039), except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The desired portion is not allowed to contain white space characters, including spaces. The desired portion may start with any number of zeros.index- The index of the sequence ofchars that starts the desired portion.endIndex- The index of the sequence ofchars that ends the desired portion. The length will be index + endIndex - 1.- Returns:
- An arbitrary-precision integer with the same value as given in the
sequence of
chars portion. - Throws:
java.lang.IllegalArgumentException- The parameterindexis less than 0,endIndexis less than 0, or either is greater than the sequence's length, orendIndexis less thanindex.java.lang.NullPointerException- The parametercsis null.
-
FromString
public static EInteger FromString(char[] cs)
Converts a sequence ofchars to an arbitrary-precision integer.- Parameters:
cs- A sequence ofchars describing an integer in base-10 (decimal) form. The sequence must contain only basic digits 0 to 9 (U+0030 to U+0039), except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The sequence is not allowed to contain white space characters, including spaces. The sequence may start with any number of zeros.- Returns:
- An arbitrary-precision integer with the same value as given in the
sequence of
chars. - Throws:
java.lang.NumberFormatException- The parametercsis in an invalid format.java.lang.NullPointerException- The parametercsis null.
-
FromRadixString
public static EInteger FromRadixString(char[] cs, int radix)
Converts a sequence ofchars to an arbitrary-precision integer in a given radix.- Parameters:
cs- A sequence ofchars described by the FromRadixSubstring method.radix- A base from 2 to 36. Depending on the radix, the sequence ofchars can use the basic digits 0 to 9 (U+0030 to U+0039) and then the basic upper-case letters A to Z (U+0041 to U+005A). For example, 0-9 in radix 10, and 0-9, then A-F in radix 16. Where a basic upper-case letter A to Z is allowed in the sequence ofchars, the corresponding basic lower-case letter (U+0061 to U+007a) is allowed instead.- Returns:
- An arbitrary-precision integer with the same value as the given
sequence of
chars. - Throws:
java.lang.NullPointerException- The parametercsis null.java.lang.NumberFormatException- The sequence ofchars is empty or in an invalid format.
-
FromRadixSubstring
public static EInteger FromRadixSubstring(char[] cs, int radix, int index, int endIndex)
Converts a portion of a sequence ofchars to an arbitrary-precision integer in a given radix.- Parameters:
cs- A text sequence ofchars. The desired portion of the sequence ofchars must contain only characters allowed by the given radix, except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The desired portion is not allowed to contain white space characters, including spaces. The desired portion may start with any number of zeros.radix- A base from 2 to 36. Depending on the radix, the sequence ofchars can use the basic digits 0 to 9 (U+0030 to U+0039) and then the basic upper-case letters A to Z (U+0041 to U+005A). For example, 0-9 in radix 10, and 0-9, then A-F in radix 16. Where a basic upper-case letter A to Z is allowed in the sequence ofchars, the corresponding basic lower-case letter (U+0061 to U+007a) is allowed instead.index- The index of the sequence ofchars that starts the desired portion.endIndex- The index of the sequence ofchars that ends the desired portion. The length will be index + endIndex - 1.- Returns:
- An arbitrary-precision integer with the same value as given in the sequence's portion.
- Throws:
java.lang.NullPointerException- The parametercsis null.java.lang.NumberFormatException- The portion is empty or in an invalid format.
-
FromSubstring
public static EInteger FromSubstring(byte[] bytes, int index, int endIndex)
Converts a portion of a sequence of bytes (interpreted as text) to an arbitrary-precision integer. Each byte in the sequence has to be a character in the Basic Latin range (0x00 to 0x7f or U+0000 to U+007F) of the Unicode Standard.- Parameters:
bytes- A sequence of bytes (interpreted as text), the desired portion of which describes an integer in base-10 (decimal) form. The desired portion of the sequence of bytes (interpreted as text) must contain only basic digits 0 to 9 (U+0030 to U+0039), except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The desired portion is not allowed to contain white space characters, including spaces. The desired portion may start with any number of zeros.index- The index of the sequence of bytes (interpreted as text) that starts the desired portion.endIndex- The index of the sequence of bytes (interpreted as text) that ends the desired portion. The length will be index + endIndex - 1.- Returns:
- An arbitrary-precision integer with the same value as given in the sequence of bytes (interpreted as text) portion.
- Throws:
java.lang.IllegalArgumentException- The parameterindexis less than 0,endIndexis less than 0, or either is greater than the sequence's length, orendIndexis less thanindex.java.lang.NullPointerException- The parameterbytesis null.
-
FromString
public static EInteger FromString(byte[] bytes)
Converts a sequence of bytes (interpreted as text) to an arbitrary-precision integer. Each byte in the sequence has to be a code point in the Basic Latin range (0x00 to 0x7f or U+0000 to U+007F) of the Unicode Standard.- Parameters:
bytes- A sequence of bytes describing an integer in base-10 (decimal) form. The sequence must contain only basic digits 0 to 9 (U+0030 to U+0039), except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The sequence is not allowed to contain white space characters, including spaces. The sequence may start with any number of zeros.- Returns:
- An arbitrary-precision integer with the same value as given in the sequence of bytes.
- Throws:
java.lang.NumberFormatException- The parameterbytesis in an invalid format.java.lang.NullPointerException- The parameterbytesis null.
-
FromRadixString
public static EInteger FromRadixString(byte[] bytes, int radix)
Converts a sequence of bytes (interpreted as text) to an arbitrary-precision integer in a given radix. Each byte in the sequence has to be a character in the Basic Latin range (0x00 to 0x7f or U+0000 to U+007F) of the Unicode Standard.- Parameters:
bytes- A sequence of bytes (interpreted as text) described by the FromRadixSubstring method.radix- A base from 2 to 36. Depending on the radix, the sequence of bytes can use the basic digits 0 to 9 (U+0030 to U+0039) and then the basic upper-case letters A to Z (U+0041 to U+005A). For example, 0-9 in radix 10, and 0-9, then A-F in radix 16. Where a basic upper-case letter A to Z is allowed in the sequence of bytes, the corresponding basic lower-case letter (U+0061 to U+007a) is allowed instead.- Returns:
- An arbitrary-precision integer with the same value as the given sequence of bytes.
- Throws:
java.lang.NullPointerException- The parameterbytesis null.java.lang.NumberFormatException- The sequence of bytes (interpreted as text) is empty or in an invalid format.
-
FromRadixSubstring
public static EInteger FromRadixSubstring(byte[] bytes, int radix, int index, int endIndex)
Converts a portion of a sequence of bytes (interpreted as text) to an arbitrary-precision integer in a given radix. Each byte in the sequence has to be a character in the Basic Latin range (0x00 to 0x7f or U+0000 to U+007F) of the Unicode Standard.- Parameters:
bytes- A sequence of bytes (interpreted as text). The desired portion of the sequence of bytes (interpreted as text) must contain only characters allowed by the given radix, except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The desired portion is not allowed to contain white space characters, including spaces. The desired portion may start with any number of zeros.radix- A base from 2 to 36. Depending on the radix, the sequence of bytes (interpreted as text) can use the basic digits 0 to 9 (U+0030 to U+0039) and then the basic upper-case letters A to Z (U+0041 to U+005A). For example, 0-9 in radix 10, and 0-9, then A-F in radix 16. Where a basic upper-case letter A to Z is allowed in the sequence of bytes (interpreted as text), the corresponding basic lower-case letter (U+0061 to U+007a) is allowed instead.index- The index of the sequence of bytes (interpreted as text) that starts the desired portion.endIndex- The index of the sequence of bytes (interpreted as text) that ends the desired portion. The length will be index + endIndex - 1.- Returns:
- An arbitrary-precision integer with the same value as given in the sequence's portion.
- Throws:
java.lang.NullPointerException- The parameterbytesis null.java.lang.NumberFormatException- The portion is empty or in an invalid format.
-
FromString
public static EInteger FromString(java.lang.String str)
Converts a string to an arbitrary-precision integer.- Parameters:
str- A text string describing an integer in base-10 (decimal) form. The string must contain only basic digits 0 to 9 (U+0030 to U+0039), except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The string is not allowed to contain white space characters, including spaces. The string may start with any number of zeros.- Returns:
- An arbitrary-precision integer with the same value as given in the string.
- Throws:
java.lang.NumberFormatException- The parameterstris in an invalid format.java.lang.NullPointerException- The parameterstris null.
-
FromSubstring
public static EInteger FromSubstring(java.lang.String str, int index, int endIndex)
Converts a portion of a string to an arbitrary-precision integer.- Parameters:
str- A text string, the desired portion of which describes an integer in base-10 (decimal) form. The desired portion of the string must contain only basic digits 0 to 9 (U+0030 to U+0039), except that it may start with a minus sign ("-", U+002D) to indicate a negative number. The desired portion is not allowed to contain white space characters, including spaces. The desired portion may start with any number of zeros.index- The index of the string that starts the string portion.endIndex- The index of the string that ends the string portion. The length will be index + endIndex - 1.- Returns:
- An arbitrary-precision integer with the same value as given in the string portion.
- Throws:
java.lang.IllegalArgumentException- The parameterindexis less than 0,endIndexis less than 0, or either is greater than the string's length, orendIndexis less thanindex.java.lang.NullPointerException- The parameterstris null.
-
Abs
public EInteger Abs()
Returns the absolute value of this object's value.- Returns:
- This object's value with the sign removed.
-
Add
public EInteger Add(EInteger bigintAugend)
Adds this arbitrary-precision integer and another arbitrary-precision integer and returns the result.- Parameters:
bigintAugend- Another arbitrary-precision integer.- Returns:
- The sum of the two numbers, that is, this arbitrary-precision integer plus another arbitrary-precision integer.
- Throws:
java.lang.NullPointerException- The parameterbigintAugendis null.
-
AsInt32Checked
@Deprecated public int AsInt32Checked()
Deprecated.Renamed to ToInt32Checked.Converts this object's value to a 32-bit signed integer, throwing an exception if it can't fit.- Returns:
- A 32-bit signed integer.
-
AsInt32Unchecked
@Deprecated public int AsInt32Unchecked()
Deprecated.Renamed to ToInt32Unchecked.Converts this object's value to a 32-bit signed integer. If the value can't fit in a 32-bit integer, returns the lower 32 bits of this object's two's-complement form (see"Forms of numbers") (in which case the return value might have a different sign than this object's value).- Returns:
- A 32-bit signed integer.
-
AsInt64Checked
@Deprecated public long AsInt64Checked()
Deprecated.Renamed to ToInt64Checked.Converts this object's value to a 64-bit signed integer, throwing an exception if it can't fit.- Returns:
- A 64-bit signed integer.
-
AsInt64Unchecked
@Deprecated public long AsInt64Unchecked()
Deprecated.Renamed to ToInt64Unchecked.Converts this object's value to a 64-bit signed integer. If the value can't fit in a 64-bit integer, returns the lower 64 bits of this object's two's-complement form (see"Forms of numbers") (in which case the return value might have a different sign than this object's value).- Returns:
- A 64-bit signed integer.
-
CanFitInInt32
public boolean CanFitInInt32()
Returns whether this object's value can fit in a 32-bit signed integer.- Returns:
trueif this object's value is from -2147483648 through 2147483647; otherwise,false.
-
CanFitInInt64
public boolean CanFitInInt64()
Returns whether this object's value can fit in a 64-bit signed integer.- Returns:
trueif this object's value is from -9223372036854775808 through 9223372036854775807; otherwise,false.
-
compareTo
public int compareTo(EInteger other)
Compares an arbitrary-precision integer with this instance.- Specified by:
compareToin interfacejava.lang.Comparable<EInteger>- Parameters:
other- The integer to compare to this value.- Returns:
- Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater. This implementation returns a positive number if.
-
Max
public static EInteger Max(EInteger first, EInteger second)
Returns the greater of two arbitrary-precision integers.- Parameters:
first- The first integer to compare.second- The second integer to compare.- Returns:
- The greater of the two integers.
- Throws:
java.lang.NullPointerException- The parameterfirstorsecondis null.
-
Min
public static EInteger Min(EInteger first, EInteger second)
Returns the smaller of two arbitrary-precision integers.- Parameters:
first- The first integer to compare.second- The second integer to compare.- Returns:
- The smaller of the two integers.
- Throws:
java.lang.NullPointerException- The parameterfirstorsecondis null.
-
MaxMagnitude
public static EInteger MaxMagnitude(EInteger first, EInteger second)
Of two arbitrary-precision integers, returns the one with the greater absolute value. If both integers have the same absolute value, this method has the same effect as Max.- Parameters:
first- The first integer to compare.second- The second integer to compare.- Returns:
- The integer with the greater absolute value.
- Throws:
java.lang.NullPointerException- The parameterfirstorsecondis null.
-
MinMagnitude
public static EInteger MinMagnitude(EInteger first, EInteger second)
Of two arbitrary-precision integers, returns the one with the smaller absolute value. If both integers have the same absolute value, this method has the same effect as Min.- Parameters:
first- The first integer to compare.second- The second integer to compare.- Returns:
- The integer with the smaller absolute value.
- Throws:
java.lang.NullPointerException- The parameterfirstorsecondis null.
-
Add
public EInteger Add(int intValue)
Adds this arbitrary-precision integer and a 32-bit signed integer and returns the result.- Parameters:
intValue- The parameterintValueis a 32-bit signed integer.- Returns:
- The sum of the two numbers, that is, this arbitrary-precision integer plus a 32-bit signed integer.
-
Subtract
public EInteger Subtract(int intValue)
Subtracts a 32-bit signed integer from this arbitrary-precision integer and returns the result.- Parameters:
intValue- The parameterintValueis a 32-bit signed integer.- Returns:
- The difference between the two numbers, that is, this arbitrary-precision integer minus a 32-bit signed integer.
-
Multiply
public EInteger Multiply(int intValue)
Multiplies this arbitrary-precision integer by a 32-bit signed integer and returns the result.EInteger result = EInteger.FromString("5").Multiply(200);.- Parameters:
intValue- The parameterintValueis a 32-bit signed integer.- Returns:
- The product of the two numbers, that is, this arbitrary-precision integer times a 32-bit signed integer.
-
Divide
public EInteger Divide(int intValue)
Divides this arbitrary-precision integer by a 32-bit signed integer and returns the result. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other 32-bit signed integer is negative, or vice versa, and will be positive if both are positive or both are negative.- Parameters:
intValue- The divisor.- Returns:
- The result of dividing this arbitrary-precision integer by a 32-bit signed integer. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other 32-bit signed integer is negative, or vice versa, and will be positive if both are positive or both are negative.
- Throws:
java.lang.ArithmeticException- Attempted to divide by zero.
-
Remainder
public EInteger Remainder(int intValue)
Returns the remainder that would result when this arbitrary-precision integer is divided by a 32-bit signed integer. The remainder is the number that remains when the absolute value of this arbitrary-precision integer is divided by the absolute value of the other 32-bit signed integer; the remainder has the same sign (positive or negative) as this arbitrary-precision integer.- Parameters:
intValue- The parameterintValueis a 32-bit signed integer.- Returns:
- The remainder that would result when this arbitrary-precision integer is divided by a 32-bit signed integer.
- Throws:
java.lang.ArithmeticException- Attempted to divide by zero.java.lang.NullPointerException- The parameterintValueis null.
-
compareTo
public int compareTo(int intValue)
Compares an arbitrary-precision integer with this instance.- Parameters:
intValue- The parameterintValueis a 32-bit signed integer.- Returns:
- Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.
-
Divide
public EInteger Divide(EInteger bigintDivisor)
Divides this arbitrary-precision integer by another arbitrary-precision integer and returns the result. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other arbitrary-precision integer is negative, or vice versa, and will be positive if both are positive or both are negative.- Parameters:
bigintDivisor- The divisor.- Returns:
- The result of dividing this arbitrary-precision integer by another arbitrary-precision integer. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other arbitrary-precision integer is negative, or vice versa, and will be positive if both are positive or both are negative.
- Throws:
java.lang.NullPointerException- The parameterbigintDivisoris null.java.lang.ArithmeticException- Attempted to divide by zero.
-
DivRem
public EInteger[] DivRem(int intDivisor)
Divides this arbitrary-precision integer by a 32-bit signed integer and returns a two-item array containing the result of the division and the remainder, in that order. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other 32-bit signed integer is negative, or vice versa, and will be positive if both are positive or both are negative. The remainder is the number that remains when the absolute value of this arbitrary-precision integer is divided by the absolute value of the other 32-bit signed integer; the remainder has the same sign (positive or negative) as this arbitrary-precision integer.- Parameters:
intDivisor- The number to divide by.- Returns:
- An array of two items: the first is the result of the division as an arbitrary-precision integer, and the second is the remainder as an arbitrary-precision integer. The result of division is the result of the Divide method on the two operands, and the remainder is the result of the Remainder method on the two operands.
- Throws:
java.lang.ArithmeticException- The parameterintDivisoris 0.
-
Add
public EInteger Add(long longValue)
Adds this arbitrary-precision integer and a 64-bit signed integer and returns the result.- Parameters:
longValue- The parameterlongValueis a 64-bit signed integer.- Returns:
- The sum of the two numbers, that is, this arbitrary-precision integer plus a 64-bit signed integer.
-
Subtract
public EInteger Subtract(long longValue)
Subtracts a 64-bit signed integer from this arbitrary-precision integer and returns the result.- Parameters:
longValue- The parameterlongValueis a 64-bit signed integer.- Returns:
- The difference between the two numbers, that is, this arbitrary-precision integer minus a 64-bit signed integer.
-
Multiply
public EInteger Multiply(long longValue)
Multiplies this arbitrary-precision integer by a 64-bit signed integer and returns the result.- Parameters:
longValue- The parameterlongValueis a 64-bit signed integer.- Returns:
- The product of the two numbers, that is, this arbitrary-precision integer times a 64-bit signed integer.
-
Divide
public EInteger Divide(long longValue)
Divides this arbitrary-precision integer by a 64-bit signed integer and returns the result. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other 64-bit signed integer is negative, or vice versa, and will be positive if both are positive or both are negative.- Parameters:
longValue- The parameterlongValueis a 64-bit signed integer.- Returns:
- The result of dividing this arbitrary-precision integer by a 64-bit signed integer. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other 64-bit signed integer is negative, or vice versa, and will be positive if both are positive or both are negative.
-
Remainder
public EInteger Remainder(long longValue)
Returns the remainder that would result when this arbitrary-precision integer is divided by a 64-bit signed integer. The remainder is the number that remains when the absolute value of this arbitrary-precision integer is divided by the absolute value of the other 64-bit signed integer; the remainder has the same sign (positive or negative) as this arbitrary-precision integer.- Parameters:
longValue- The parameterlongValueis a 64-bit signed integer.- Returns:
- The remainder that would result when this arbitrary-precision integer is divided by a 64-bit signed integer.
-
compareTo
public int compareTo(long longValue)
Compares an arbitrary-precision integer with this instance.- Parameters:
longValue- The parameterlongValueis a 64-bit signed integer.- Returns:
- Zero if the values are equal; a negative number if this instance is less, or a positive number if this instance is greater.
-
DivRem
public EInteger[] DivRem(long intDivisor)
Divides this arbitrary-precision integer by a 64-bit signed integer and returns a two-item array containing the result of the division and the remainder, in that order. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other 64-bit signed integer is negative, or vice versa, and will be positive if both are positive or both are negative. The remainder is the number that remains when the absolute value of this arbitrary-precision integer is divided by the absolute value of the other 64-bit signed integer; the remainder has the same sign (positive or negative) as this arbitrary-precision integer.- Parameters:
intDivisor- The parameterintDivisoris a 64-bit signed integer.- Returns:
- An array of two items: the first is the result of the division as an arbitrary-precision integer, and the second is the remainder as an arbitrary-precision integer. The result of division is the result of the Divide method on the two operands, and the remainder is the result of the Remainder method on the two operands.
-
DivRem
public EInteger[] DivRem(EInteger divisor)
Divides this arbitrary-precision integer by another arbitrary-precision integer and returns a two-item array containing the result of the division and the remainder, in that order. The result of the division is rounded down (the fractional part is discarded). Except if the result of the division is 0, it will be negative if this arbitrary-precision integer is positive and the other arbitrary-precision integer is negative, or vice versa, and will be positive if both are positive or both are negative. The remainder is the number that remains when the absolute value of this arbitrary-precision integer is divided by the absolute value of the other arbitrary-precision integer; the remainder has the same sign (positive or negative) as this arbitrary-precision integer.- Parameters:
divisor- The number to divide by.- Returns:
- An array of two items: the first is the result of the division as an arbitrary-precision integer, and the second is the remainder as an arbitrary-precision integer. The result of division is the result of the Divide method on the two operands, and the remainder is the result of the Remainder method on the two operands.
- Throws:
java.lang.ArithmeticException- The parameterdivisoris 0.java.lang.NullPointerException- The parameterdivisoris null.
-
equals
public boolean equals(java.lang.Object obj)
Determines whether this object and another object are equal and have the same type.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- The parameterobjis an arbitrary object.- Returns:
trueif this object and another object are equal; otherwise,false.
-
Gcd
public EInteger Gcd(EInteger bigintSecond)
Returns the greatest common divisor of this integer and the given integer. The greatest common divisor (GCD) is also known as the greatest common factor (GCF). This method works even if either or both integers are negative.- Parameters:
bigintSecond- Another arbitrary-precision integer. Can be negative.- Returns:
- The greatest common divisor of this integer and the given integer.
- Throws:
java.lang.NullPointerException- The parameterbigintSecondis null.java.lang.ArithmeticException- Attempted to divide by zero.java.lang.IllegalArgumentException- BigPower is negative.
-
GetDigitCountAsEInteger
public EInteger GetDigitCountAsEInteger()
Returns the number of decimal digits used by this integer, in the form of an arbitrary-precision integer.- Returns:
- The number of digits in the decimal form of this integer. Returns 1 if this number is 0.
-
GetDigitCount
@Deprecated public int GetDigitCount()
Deprecated.This method may overflow. Use GetDigitCountAsEInteger instead.Returns the number of decimal digits used by this integer.- Returns:
- The number of digits in the decimal form of this integer. Returns 1 if this number is 0.
- Throws:
java.lang.ArithmeticException- The return value would exceed the range of a 32-bit signed integer.
-
GetDigitCountAsInt64
public long GetDigitCountAsInt64()
Returns the number of decimal digits used by this integer, in the form of a 64-bit signed integer.- Returns:
- The number of digits in the decimal form of this integer. Returns 1
if this number is 0. Returns 2^63 - 1(
Long.MAX_VALUEin.NET orLong.MAX_VALUEin Java) if the number of decimal digits is 2^63 - 1 or greater. (UseGetDigitCountAsEIntegerinstead if the application relies on the exact number of decimal digits.).
-
hashCode
public int hashCode()
Returns the hash code for this instance. No application or process IDs are used in the hash code calculation.- Overrides:
hashCodein classjava.lang.Object- Returns:
- A 32-bit signed integer.
-
GetLowBit
@Deprecated public int GetLowBit()
Deprecated.This method may overflow. Use GetLowBitAsEInteger instead.Gets the bit position of the lowest set bit in this number's absolute value. (This will also be the position of the lowest set bit in the number's two's-complement form (see"Forms of numbers").).- Returns:
- The bit position of the lowest bit set in the number's absolute value, starting at 0. Returns -1 if this value is 0.
-
GetLowBitAsInt64
public long GetLowBitAsInt64()
Gets the bit position of the lowest set bit in this number's absolute value, in the form of a 64-bit signed integer. (This will also be the position of the lowest set bit in the number's two's-complement form (see"Forms of numbers").).- Returns:
- The bit position of the lowest bit set in the number's absolute
value, starting at 0. Returns -1 if this value is 0 or odd. Returns
2^63 - 1 (
Long.MAX_VALUEin.NET orLong.MAX_VALUEin Java) if this number is other than zero but the lowest set bit is at 2^63 - 1 or greater. (UseGetLowBitAsEIntegerinstead if the application relies on the exact value of the lowest set bit position.).
-
GetLowBitAsEInteger
public EInteger GetLowBitAsEInteger()
Gets the bit position of the lowest set bit in this number's absolute value, in the form of an arbitrary-precision integer. (This will also be the position of the lowest set bit in the number's two's-complement form (see"Forms of numbers").).- Returns:
- The bit position of the lowest bit set in the number's absolute value, starting at 0. Returns -1 if this value is 0 or odd.
-
GetSignedBit
public boolean GetSignedBit(EInteger bigIndex)
Returns whether a bit is set in the two's-complement form (see"Forms of numbers") of this object's value.- Parameters:
bigIndex- The index, starting at zero, of the bit to test, where 0 is the least significant bit, 1 is the next least significant bit, and so on.- Returns:
trueif the given bit is set in the two' s-complement form (seeEDecimal) of this object's value; otherwise,false.- Throws:
java.lang.NullPointerException- The parameterbigIndexis null.
-
GetSignedBit
public boolean GetSignedBit(int index)
Returns whether a bit is set in the two's-complement form (see"Forms of numbers") of this object's value.- Parameters:
index- The index, starting at 0, of the bit to test, where 0 is the least significant bit, 1 is the next least significant bit, and so on.- Returns:
trueif the given bit is set in the two' s-complement form (seeEDecimal) of this object's value; otherwise,false.
-
GetSignedBitLengthAsEInteger
public EInteger GetSignedBitLengthAsEInteger()
Finds the minimum number of bits needed to represent this object's value, except for its sign, and returns that number of bits as an arbitrary-precision integer. If the value is negative, finds the number of bits in the value equal to this object's absolute value minus 1. For example, all integers in the interval [-(2^63), (2^63) - 1], which is the same as the range of integers in Java's and.NET'slongtype, have a signed bit length of 63 or less, and all other integers have a signed bit length of greater than 63.- Returns:
- The number of bits in this object's value, except for its sign. Returns 0 if this object's value is 0 or negative 1.
-
GetSignedBitLengthAsInt64
public long GetSignedBitLengthAsInt64()
Finds the minimum number of bits needed to represent this object's value, except for its sign, and returns that number of bits as a 64-bit signed integer. If the value is negative, finds the number of bits in the value equal to this object's absolute value minus 1. For example, all integers in the interval [-(2^63), (2^63) - 1], which is the same as the range of integers in Java's and.NET'slongtype, have a signed bit length of 63 or less, and all other integers have a signed bit length of greater than 63.- Returns:
- The number of bits in this object's value, except for its sign.
Returns 0 if this object's value is 0 or negative 1. If the return
value would be greater than 2^63 - 1 (
Long.MAX_VALUEin.NET orLong.MAX_VALUEin Java), returns 2^63 - 1 instead. (UseGetSignedBitLengthAsEIntegerinstead of this method if the application relies on the exact number of bits.).
-
GetSignedBitLength
@Deprecated public int GetSignedBitLength()
Deprecated.This method may overflow. Use GetSignedBitLengthAsEInteger instead.Finds the minimum number of bits needed to represent this object's value, except for its sign. If the value is negative, finds the number of bits in the value equal to this object's absolute value minus 1. For example, all integers in the interval [-(2^63), (2^63) - 1], which is the same as the range of integers in Java's and.NET'slongtype, have a signed bit length of 63 or less, and all other integers have a signed bit length of greater than 63.- Returns:
- The number of bits in this object's value, except for its sign. Returns 0 if this object's value is 0 or negative 1.
- Throws:
java.lang.ArithmeticException- The return value would exceed the range of a 32-bit signed integer.
-
GetUnsignedBit
public boolean GetUnsignedBit(EInteger bigIndex)
Returns whether a bit is set in this number's absolute value.- Parameters:
bigIndex- The index, starting at zero, of the bit to test, where 0 is the least significant bit, 1 is the next least significant bit, and so on.- Returns:
trueif the given bit is set in this number's absolute value.- Throws:
java.lang.NullPointerException- The parameterbigIndexis null.
-
GetUnsignedBit
public boolean GetUnsignedBit(int index)
Returns whether a bit is set in this number's absolute value.- Parameters:
index- The index, starting at 0, of the bit to test, where 0 is the least significant bit, 1 is the next least significant bit, and so on.- Returns:
trueif the given bit is set in this number's absolute value.
-
GetUnsignedBitLengthAsEInteger
public EInteger GetUnsignedBitLengthAsEInteger()
Finds the minimum number of bits needed to represent this number's absolute value, and returns that number of bits as an arbitrary-precision integer. For example, all integers in the interval [-((2^63) - 1), (2^63) - 1] have an unsigned bit length of 63 or less, and all other integers have an unsigned bit length of greater than 63. This interval is not the same as the range of integers in Java's and.NET'slongtype.- Returns:
- The number of bits in this object's absolute value. Returns 0 if this object's value is 0, and returns 1 if the value is negative 1.
-
GetUnsignedBitLengthAsInt64
public long GetUnsignedBitLengthAsInt64()
Finds the minimum number of bits needed to represent this number's absolute value, and returns that number of bits as a 64-bit signed integer. For example, all integers in the interval [-((2^63) - 1), (2^63) - 1] have an unsigned bit length of 63 or less, and all other integers have an unsigned bit length of greater than 63. This interval is not the same as the range of integers in Java's and.NET'slongtype.- Returns:
- The number of bits in this object's absolute value. Returns 0 if
this object's value is 0, and returns 1 if the value is negative 1.
If the return value would be greater than 2^63 - 1(
Long.MAX_VALUEin.NET orLong.MAX_VALUEin Java), returns 2^63 - 1 instead. (UseGetUnsignedBitLengthAsEIntegerinstead of this method if the application relies on the exact number of bits.).
-
GetUnsignedBitLength
@Deprecated public int GetUnsignedBitLength()
Deprecated.This method may overflow. Use GetUnsignedBitLengthAsEInteger instead.Finds the minimum number of bits needed to represent this number's absolute value. For example, all integers in the interval [-((2^63) - 1), (2^63) - 1] have an unsigned bit length of 63 or less, and all other integers have an unsigned bit length of greater than 63. This interval is not the same as the range of integers in Java's and.NET'slongtype.- Returns:
- The number of bits in this object's absolute value. Returns 0 if this object's value is 0, and returns 1 if the value is negative 1.
- Throws:
java.lang.ArithmeticException- The return value would exceed the range of a 32-bit signed integer.
-
Mod
public EInteger Mod(EInteger divisor)
Finds the modulus remainder that results when this instance is divided by the value of an arbitrary-precision integer. The modulus remainder is the same as the normal remainder if the normal remainder is positive, and equals divisor plus normal remainder if the normal remainder is negative.- Parameters:
divisor- The number to divide by.- Returns:
- An arbitrary-precision integer.
- Throws:
java.lang.IllegalArgumentException- The parameterdivisoris less than 0.java.lang.NullPointerException- The parameterdivisoris null.
-
Mod
public EInteger Mod(int smallDivisor)
Finds the modulus remainder that results when this instance is divided by the value of another integer. The modulus remainder is the same as the normal remainder if the normal remainder is positive, and equals divisor plus normal remainder if the normal remainder is negative.- Parameters:
smallDivisor- The divisor of the modulus.- Returns:
- The modulus remainder.
- Throws:
java.lang.IllegalArgumentException- The parametersmallDivisoris less than 0.
-
ModPow
public EInteger ModPow(EInteger pow, EInteger mod)
Calculates the remainder when this arbitrary-precision integer raised to a certain power is divided by another arbitrary-precision integer.- Parameters:
pow- The power to raise this integer by.mod- The integer to divide the raised number by.- Returns:
- An arbitrary-precision integer.
- Throws:
java.lang.NullPointerException- The parameterpowormodis null.
-
Multiply
public EInteger Multiply(EInteger bigintMult)
Multiplies this arbitrary-precision integer by another arbitrary-precision integer and returns the result.- Parameters:
bigintMult- Another arbitrary-precision integer.- Returns:
- The product of the two numbers, that is, this arbitrary-precision integer times another arbitrary-precision integer.
- Throws:
java.lang.NullPointerException- The parameterbigintMultis null.
-
Negate
public EInteger Negate()
Gets the value of this object with the sign reversed.- Returns:
- This object's value with the sign reversed.
-
Pow
public EInteger Pow(long longPower)
Raises an arbitrary-precision integer to a power.- Parameters:
longPower- The exponent to raise this integer to.- Returns:
- The result. Returns 1 if
longPoweris 0. - Throws:
java.lang.IllegalArgumentException- BigPower is negative.
-
Pow
public EInteger Pow(EInteger bigPower)
Raises an arbitrary-precision integer to a power.- Parameters:
bigPower- The exponent to raise this integer to.- Returns:
- The result. Returns 1 if
bigPoweris 0. - Throws:
java.lang.NullPointerException- The parameterbigPoweris null.java.lang.IllegalArgumentException- BigPower is negative.
-
Pow
public EInteger Pow(int powerSmall)
Raises an arbitrary-precision integer to a power.- Parameters:
powerSmall- The exponent to raise this integer to.- Returns:
- The result. Returns 1 if
powerSmallis 0.
-
PowBigIntVar
@Deprecated public EInteger PowBigIntVar(EInteger power)
Deprecated.Use Pow instead.Raises an arbitrary-precision integer to a power, which is given as another arbitrary-precision integer.- Parameters:
power- The exponent to raise to.- Returns:
- The result. Returns 1 if
poweris 0. - Throws:
java.lang.IllegalArgumentException- The parameterpoweris less than 0.java.lang.NullPointerException- The parameterpoweris null.
-
Remainder
public EInteger Remainder(EInteger divisor)
Returns the remainder that would result when this arbitrary-precision integer is divided by another arbitrary-precision integer. The remainder is the number that remains when the absolute value of this arbitrary-precision integer is divided by the absolute value of the other arbitrary-precision integer; the remainder has the same sign (positive or negative) as this arbitrary-precision integer.- Parameters:
divisor- The number to divide by.- Returns:
- The remainder that would result when this arbitrary-precision integer is divided by another arbitrary-precision integer.
- Throws:
java.lang.ArithmeticException- Attempted to divide by zero.java.lang.NullPointerException- The parameterdivisoris null.
-
ShiftRight
public EInteger ShiftRight(EInteger eshift)
Returns an arbitrary-precision integer with the bits shifted to the right. For this operation, the arbitrary-precision integer is treated as a two's-complement form (see"Forms of numbers"). Thus, for negative values, the arbitrary-precision integer is sign-extended.- Parameters:
eshift- The number of bits to shift. Can be negative, in which case this is the same as ShiftLeft with the absolute value of this parameter.- Returns:
- An arbitrary-precision integer.
- Throws:
java.lang.NullPointerException- The parametereshiftis null.
-
ShiftLeft
public EInteger ShiftLeft(EInteger eshift)
Returns an arbitrary-precision integer with the bits shifted to the left by a number of bits given as an arbitrary-precision integer. A value of 1 doubles this value, a value of 2 multiplies it by 4, a value of 3 by 8, a value of 4 by 16, and so on.- Parameters:
eshift- The number of bits to shift. Can be negative, in which case this is the same as ShiftRight with the absolute value of this parameter.- Returns:
- An arbitrary-precision integer.
- Throws:
java.lang.NullPointerException- The parametereshiftis null.
-
ShiftLeft
public EInteger ShiftLeft(int numberBits)
Returns an arbitrary-precision integer with the bits shifted to the left by a number of bits. A value of 1 doubles this value, a value of 2 multiplies it by 4, a value of 3 by 8, a value of 4 by 16, and so on.- Parameters:
numberBits- The number of bits to shift. Can be negative, in which case this is the same as shiftRight with the absolute value of this parameter.- Returns:
- An arbitrary-precision integer.
-
Not
public EInteger Not()
Returns an arbitrary-precision integer with every bit flipped from this one (also called an inversion or NOT operation).- Returns:
- An arbitrary-precision integer in which each bit in its two's
complement representation is set if the corresponding bit of this
integer is clear, and vice versa. Returns -1 if this integer is 0.
If this integer is positive, the return value is negative, and vice
versa. This method uses the two's complement form of negative
integers (see
EDecimal). For example, in binary, NOT 10100 =...11101011 (or in decimal, NOT 20 = -21). In binary, NOT...11100110 = 11001 (or in decimal, NOT -26 = 25).
-
LowBits
public EInteger LowBits(long longBitCount)
Extracts the lowest bits of this integer. This is equivalent toAnd(2^longBitCount - 1), but is more efficient when this integer is non-negative and longBitCount's value is large.- Parameters:
longBitCount- The number of bits to extract from the lowest part of this integer.- Returns:
- A value equivalent to
And(2^longBitCount - 1).
-
LowBits
public EInteger LowBits(int bitCount)
Extracts the lowest bits of this integer. This is equivalent toAnd(2^bitCount - 1), but is more efficient when this integer is non-negative and bitCount's value is large.- Parameters:
bitCount- The number of bits to extract from the lowest part of this integer.- Returns:
- A value equivalent to
And(2^bitCount - 1).
-
LowBits
public EInteger LowBits(EInteger bigBitCount)
Extracts the lowest bits of this integer. This is equivalent toAnd(2^bigBitCount - 1), but is more efficient when this integer is non-negative and bigBitCount's value is large.- Parameters:
bigBitCount- The number of bits to extract from the lowest part of this integer.- Returns:
- A value equivalent to
And(2^bigBitCount - 1). - Throws:
java.lang.NullPointerException- The parameterbigBitCountis null.
-
And
public EInteger And(EInteger other)
Does an AND operation between this arbitrary-precision integer and another one.Each arbitrary-precision integer is treated as a two's-complement form (see
"Forms of numbers") for the purposes of this operator.- Parameters:
other- Another arbitrary-precision integer that participates in the operation.- Returns:
- An arbitrary-precision integer in which each bit is set if the
corresponding bits of this integer and the other integer (in their
two's-complement representation) are both set. For example, in
binary, 10110 AND 01100 = 00100 (or in decimal, 22 AND 12 = 4). This
method uses the two's complement form of negative integers (see
EDecimal). For example, in binary, ...11100111 AND 01100 = 00100 (or in decimal, -25 AND 12 = 4). - Throws:
java.lang.NullPointerException- The parameterotheris null.
-
Or
public EInteger Or(EInteger second)
Does an OR operation between this arbitrary-precision integer and another one.Each arbitrary-precision integer is treated as a two's-complement form (see
"Forms of numbers") for the purposes of this operator.- Parameters:
second- Another arbitrary-precision integer that participates in the operation.- Returns:
- An arbitrary-precision integer in which each bit is set if the
corresponding bit of this integer is set, the other integer's
corresponding bit is set, or both. For example, in binary, 10110 OR
11010 = 11110 (or in decimal, 22 OR 26 = 30). This method uses the
two's complement form of negative integers (see
EDecimal). For example, in binary, ...11101110 OR 01011 =...11101111 (or in decimal, -18 OR 11 = -17). - Throws:
java.lang.NullPointerException- The parametersecondis null.
-
AndNot
public EInteger AndNot(EInteger second)
Does an AND NOT operation between this arbitrary-precision integer and another one.Each arbitrary-precision integer is treated as a two's-complement form (see
"Forms of numbers") for the purposes of this operator.- Parameters:
second- Another arbitrary-precision integer that participates in the operation.- Returns:
- An arbitrary-precision integer in which each bit is set if the
corresponding bit of this integer is set, and the other integer's
corresponding bit is not set. For example, in binary, 10110 AND NOT
11010 = 00100 (or in decimal, 22 AND NOT 26 = 4). This method uses
the two's complement form of negative integers (see
EDecimal). For example, in binary, ...11101110 AND NOT 01011 = 00100 (or in decimal, -18 OR 11 = 4). - Throws:
java.lang.NullPointerException- The parametersecondis null.
-
OrNot
public EInteger OrNot(EInteger second)
Does an OR NOT operation between this arbitrary-precision integer and another one.Each arbitrary-precision integer is treated as a two's-complement form (see
"Forms of numbers") for the purposes of this operator.- Parameters:
second- Another arbitrary-precision integer that participates in the operation.- Returns:
- An arbitrary-precision integer in which each bit is set if the
corresponding bit of this integer is set, the other integer's
corresponding bit is not set, or both. For example, in binary, 10110
OR NOT 11010 = 00100 (or in decimal, 22 OR NOT 26 = 23). This method
uses the two's complement form of negative integers (see
EDecimal). For example, in binary, ...11101110 OR NOT 01011 =...11111110 (or in decimal, -18 OR 11 = -2). - Throws:
java.lang.NullPointerException- The parametersecondis null.
-
Imp
public EInteger Imp(EInteger second)
Does an OR NOT operation between this arbitrary-precision integer and another one.Each arbitrary-precision integer is treated as a two's-complement form (see
"Forms of numbers") for the purposes of this operator.- Parameters:
second- Another arbitrary-precision integer that participates in the operation.- Returns:
- An arbitrary-precision integer in which each bit is set if the
corresponding bit of this integer is set, the other integer's
corresponding bit is not set, or both. For example, in binary, 10110
OR NOT 11010 = 00100 (or in decimal, 22 OR NOT 26 = 23). This method
uses the two's complement form of negative integers (see
EDecimal). For example, in binary, ...11101110 OR NOT 01011 =...11111110 (or in decimal, -18 OR 11 = -2). - Throws:
java.lang.NullPointerException- The parametersecondis null.
-
XorNot
public EInteger XorNot(EInteger second)
Does an XOR NOT operation (or equivalence operation, EQV operation, or exclusive-OR NOT operation) between this arbitrary-precision integer and another one.Each arbitrary-precision integer is treated as a two's-complement form (see
"Forms of numbers") for the purposes of this operator.- Parameters:
second- Another arbitrary-precision integer that participates in the operation.- Returns:
- An arbitrary-precision integer in which each bit is set if the
corresponding bit of this integer is set or the other integer's
corresponding bit is not set, but not both. For example, in binary,
10110 XOR NOT 11010 = 10011 (or in decimal, 22 XOR NOT 26 = 19).
This method uses the two's complement form of negative integers (see
EDecimal). For example, in binary, ...11101110 XOR NOT 01011 =...11111010 (or in decimal, -18 OR 11 = -6). - Throws:
java.lang.NullPointerException- The parametersecondis null.
-
Eqv
public EInteger Eqv(EInteger second)
Does an XOR NOT operation (or equivalence operation, EQV operation, or exclusive-OR NOT operation) between this arbitrary-precision integer and another one.Each arbitrary-precision integer is treated as a two's-complement form (see
"Forms of numbers") for the purposes of this operator.- Parameters:
second- Another arbitrary-precision integer that participates in the operation.- Returns:
- An arbitrary-precision integer in which each bit is set if the
corresponding bit of this integer is set or the other integer's
corresponding bit is not set, but not both. For example, in binary,
10110 XOR NOT 11010 = 10011 (or in decimal, 22 XOR NOT 26 = 19).
This method uses the two's complement form of negative integers (see
EDecimal). For example, in binary, ...11101110 XOR NOT 01011 =...11111010 (or in decimal, -18 OR 11 = -6). - Throws:
java.lang.NullPointerException- The parametersecondis null.
-
Xor
public EInteger Xor(EInteger other)
Does an exclusive OR (XOR) operation between this arbitrary-precision integer and another one.- Parameters:
other- Another arbitrary-precision integer that participates in the operation.- Returns:
- An arbitrary-precision integer in which each bit is set if the
corresponding bit is set in one input integer but not in the other.
For example, in binary, 11010 XOR 01001 = 10011 (or in decimal, 26
XOR 9 = 19). This method uses the two's complement form of negative
integers (see
EDecimal). For example, in binary, ...11101101 XOR 00011 =...11101110 (or in decimal, -19 XOR 3 = -18). - Throws:
java.lang.NullPointerException- The parameterotheris null.
-
ShiftRight
public EInteger ShiftRight(int numberBits)
Returns an arbitrary-precision integer with the bits shifted to the right. For this operation, the arbitrary-precision integer is treated as a two's-complement form (see"Forms of numbers"). Thus, for negative values, the arbitrary-precision integer is sign-extended.- Parameters:
numberBits- The number of bits to shift. Can be negative, in which case this is the same as shiftLeft with the absolute value of this parameter.- Returns:
- An arbitrary-precision integer.
-
Sqrt
public EInteger Sqrt()
Finds the square root of this instance's value, rounded down.- Returns:
- The square root of this object's value. Returns 0 if this value is 0 or less.
-
SqrtRem
public EInteger[] SqrtRem()
Calculates the square root and the remainder.- Returns:
- An array of two arbitrary-precision integers: the first integer is the square root, and the second is the difference between this value and the square of the first integer. Returns two zeros if this value is 0 or less, or one and zero if this value equals 1.
-
Root
public EInteger Root(EInteger root)
Finds the nth root of this instance's value, rounded down.- Parameters:
root- The root to find; must be 1 or greater. If this value is 2, this method finds the square root; if 3, the cube root, and so on.- Returns:
- The square root of this object's value. Returns 0 if this value is 0 or less.
- Throws:
java.lang.NullPointerException- The parameterrootis null.
-
RootRem
public EInteger[] RootRem(EInteger root)
Calculates the nth root and the remainder.- Parameters:
root- The root to find; must be 1 or greater. If this value is 2, this method finds the square root; if 3, the cube root, and so on.- Returns:
- An array of two arbitrary-precision integers: the first integer is the nth root, and the second is the difference between this value and the nth power of the first integer. Returns two zeros if this value is 0 or less, or one and zero if this value equals 1.
- Throws:
java.lang.NullPointerException- The parameterrootis null.
-
Root
public EInteger Root(int root)
Finds the nth root of this instance's value, rounded down.- Parameters:
root- The root to find; must be 1 or greater. If this value is 2, this method finds the square root; if 3, the cube root, and so on.- Returns:
- The square root of this object's value. Returns 0 if this value is 0 or less.
-
RootRem
public EInteger[] RootRem(int root)
Calculates the nth root and the remainder.- Parameters:
root- The root to find; must be 1 or greater. If this value is 2, this method finds the square root; if 3, the cube root, and so on.- Returns:
- An array of two arbitrary-precision integers: the first integer is the nth root, and the second is the difference between this value and the nth power of the first integer. Returns two zeros if this value is 0 or less, or one and zero if this value equals 1.
-
Subtract
public EInteger Subtract(EInteger subtrahend)
Subtracts an arbitrary-precision integer from this arbitrary-precision integer and returns the result.- Parameters:
subtrahend- Another arbitrary-precision integer.- Returns:
- The difference between the two numbers, that is, this arbitrary-precision integer minus another arbitrary-precision integer.
- Throws:
java.lang.NullPointerException- The parametersubtrahendis null.
-
ToBytes
public byte[] ToBytes(boolean littleEndian)
Returns a byte array of this integer's value. The byte array will take the number's two's-complement form (see"Forms of numbers"), using the fewest bytes necessary to store its value unambiguously. If this value is negative, the bits that appear beyond the most significant bit of the number will be all ones. The resulting byte array can be passed to theFromBytes()method (with the same byte order) to reconstruct this integer's value.- Parameters:
littleEndian- See the 'littleEndian' parameter of theFromBytes()method.- Returns:
- A byte array. If this value is 0, returns a byte array with the single element 0.
-
ToInt32Checked
public int ToInt32Checked()
Converts this object's value to a 32-bit signed integer, throwing an exception if it can't fit.- Returns:
- A 32-bit signed integer.
-
ToInt32Unchecked
public int ToInt32Unchecked()
Converts this object's value to a 32-bit signed integer. If the value can't fit in a 32-bit integer, returns the lower 32 bits of this object's two's-complement form (see"Forms of numbers") (in which case the return value might have a different sign than this object's value).- Returns:
- A 32-bit signed integer.
-
ToInt64Checked
public long ToInt64Checked()
Converts this object's value to a 64-bit signed integer, throwing an exception if it can't fit.- Returns:
- A 64-bit signed integer.
-
ToInt64Unchecked
public long ToInt64Unchecked()
Converts this object's value to a 64-bit signed integer. If the value can't fit in a 64-bit integer, returns the lower 64 bits of this object's two's-complement form (see"Forms of numbers") (in which case the return value might have a different sign than this object's value).- Returns:
- A 64-bit signed integer.
-
ToRadixString
public java.lang.String ToRadixString(int radix)
Generates a string representing the value of this object, in the given radix.- Parameters:
radix- A radix from 2 through 36. For example, to generate a hexadecimal (base-16) string, specify 16. To generate a decimal (base-10) string, specify 10.- Returns:
- A string representing the value of this object. If this value is 0, returns "0". If negative, the string will begin with a minus sign ("-", U+002D). Depending on the radix, the string will use the basic digits 0 to 9 (U+0030 to U+0039) and then the basic upper-case letters A to Z (U+0041 to U+005A). For example, 0-9 in radix 10, and 0-9, then A-F in radix 16.
-
toString
public java.lang.String toString()
Converts this object to a text string in base 10.- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of this object. If this value is 0, returns "0". If negative, the string will begin with a minus sign ("-", U+002D). The string will use the basic digits 0 to 9 (U+0030 to U+0039).
-
Increment
public EInteger Increment()
Returns one added to this arbitrary-precision integer.- Returns:
- The given arbitrary-precision integer plus one.
-
Decrement
public EInteger Decrement()
Returns one subtracted from this arbitrary-precision integer.- Returns:
- The given arbitrary-precision integer minus one.
-
ToByteChecked
public byte ToByteChecked()
Converts this number's value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255).- Returns:
- This number's value as a byte (from 0 to 255).
- Throws:
java.lang.ArithmeticException- This value is less than 0 or greater than 255.
-
ToByteUnchecked
public byte ToByteUnchecked()
Converts this number to a byte (from 0 to 255), returning the least-significant bits of this number's two's-complement form.- Returns:
- This number, converted to a byte (from 0 to 255).
-
FromByte
public static EInteger FromByte(byte inputByte)
Converts a byte (from 0 to 255) to an arbitrary-precision integer.- Parameters:
inputByte- The number to convert as a byte (from 0 to 255).- Returns:
- This number's value as an arbitrary-precision integer.
-
ToInt16Checked
public short ToInt16Checked()
Converts this number's value to a 16-bit signed integer if it can fit in a 16-bit signed integer.- Returns:
- This number's value as a 16-bit signed integer.
- Throws:
java.lang.ArithmeticException- This value is less than -32768 or greater than 32767.
-
ToInt16Unchecked
public short ToInt16Unchecked()
Converts this number to a 16-bit signed integer, returning the least-significant bits of this number's two's-complement form.- Returns:
- This number, converted to a 16-bit signed integer.
-
FromInt16
public static EInteger FromInt16(short inputInt16)
Converts a 16-bit signed integer to an arbitrary-precision integer.- Parameters:
inputInt16- The number to convert as a 16-bit signed integer.- Returns:
- This number's value as an arbitrary-precision integer.
-
-