public final class EInteger extends Object implements Comparable<EInteger>
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.
| Modifier and Type | Method and Description |
|---|---|
EInteger |
Abs()
Returns the absolute value of this object's value.
|
EInteger |
Add(EInteger bigintAugend)
Adds this object and another object.
|
int |
AsInt32Checked()
Deprecated.
Renamed to ToInt32Checked.
|
int |
AsInt32Unchecked()
Deprecated.
Renamed to ToInt32Unchecked.
|
long |
AsInt64Checked()
Deprecated.
Renamed to ToInt64Checked.
|
long |
AsInt64Unchecked()
Deprecated.
Renamed to ToInt64Unchecked.
|
boolean |
CanFitInInt32()
Returns whether this object's value can fit in a 32-bit signed integer.
|
boolean |
CanFitInInt64()
Returns whether this object's value can fit in a 64-bit signed integer.
|
int |
compareTo(EInteger other)
Compares an arbitrary-precision integer with this instance.
|
EInteger |
Divide(EInteger bigintDivisor)
Divides this instance by the value of an arbitrary-precision integer.
|
EInteger[] |
DivRem(EInteger divisor)
Divides this object by another arbitrary-precision integer and returns the
quotient and remainder.
|
boolean |
equals(Object obj)
Determines whether this object and another object are equal and have the
same type.
|
static EInteger |
FromByte(byte inputByte)
Converts a byte (from 0 to 255) to an arbitrary-precision integer.
|
static EInteger |
FromBytes(byte[] bytes,
boolean littleEndian)
Initializes an arbitrary-precision integer from an array of bytes.
|
static EInteger |
FromInt16(short inputInt16)
Converts a 16-bit signed integer to an arbitrary-precision integer.
|
static EInteger |
FromInt32(int intValue)
Converts a 32-bit signed integer to an arbitrary-precision integer.
|
static EInteger |
FromInt64(long longerValue)
Converts a 64-bit signed integer to an arbitrary-precision integer.
|
static EInteger |
FromRadixString(String str,
int radix)
Not documented yet.
|
static EInteger |
FromRadixSubstring(String str,
int radix,
int index,
int endIndex)
Converts a portion of a string to an arbitrary-precision integer in a given
radix.
|
static EInteger |
FromString(String str)
Converts a string to an arbitrary-precision integer.
|
static EInteger |
FromSubstring(String str,
int index,
int endIndex)
Converts a portion of a string to an arbitrary-precision integer.
|
EInteger |
Gcd(EInteger bigintSecond)
Returns the greatest common divisor of two integers.
|
int |
GetDigitCount()
Not documented yet.
|
int |
GetLowBit()
Gets the lowest set bit in this number's absolute value.
|
EInteger |
GetLowBitAsEInteger()
Gets the lowest set bit in this number's absolute value.
|
static EInteger |
getOne()
Gets the number 1 as an arbitrary-precision integer.
|
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. |
int |
GetSignedBitLength()
Finds the minimum number of bits needed to represent this object's
value, except for its sign.
|
static EInteger |
getTen()
Gets the number 10 as an arbitrary-precision integer.
|
boolean |
GetUnsignedBit(int index)
Returns whether a bit is set in this number's absolute value.
|
int |
GetUnsignedBitLength()
Finds the minimum number of bits needed to represent this number's
absolute value.
|
EInteger |
GetUnsignedBitLengthAsEInteger()
Finds the minimum number of bits needed to represent this number's
absolute value.
|
static EInteger |
getZero()
Gets a value not documented yet.
|
int |
hashCode()
Returns the hash code for this instance.
|
boolean |
isEven()
Gets a value indicating whether this value is even.
|
boolean |
isPowerOfTwo()
Gets a value indicating whether this object's value is a power of two.
|
boolean |
isZero()
Gets a value indicating whether this value is 0.
|
EInteger |
Mod(EInteger divisor)
Finds the modulus remainder that results when this instance is divided by
the value of an arbitrary-precision integer.
|
EInteger |
ModPow(EInteger pow,
EInteger mod)
Calculates the remainder when an arbitrary-precision integer raised to a
certain power is divided by another arbitrary-precision integer.
|
EInteger |
Multiply(EInteger bigintMult)
Multiplies this instance by the value of an arbitrary-precision integer
object.
|
EInteger |
Negate()
Gets the value of this object with the sign reversed.
|
EInteger |
Pow(int powerSmall)
Raises an arbitrary-precision integer to a power.
|
EInteger |
PowBigIntVar(EInteger power)
Raises an arbitrary-precision integer to a power, which is given as another
arbitrary-precision integer.
|
EInteger |
Remainder(EInteger divisor)
Finds the remainder that results when this instance is divided by the value
of an arbitrary-precision integer.
|
EInteger |
ShiftLeft(int numberBits)
Returns an arbitrary-precision integer with the bits shifted to the left by
a number of bits.
|
EInteger |
ShiftRight(int numberBits)
Returns an arbitrary-precision integer with the bits shifted to the right.
|
int |
signum()
Gets the sign of this object's value.
|
EInteger |
Sqrt()
Finds the square root of this instance's value, rounded down.
|
EInteger[] |
SqrtRem()
Calculates the square root and the remainder.
|
EInteger |
Subtract(EInteger subtrahend)
Subtracts an arbitrary-precision integer from this arbitrary-precision
integer.
|
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).
|
byte[] |
ToBytes(boolean littleEndian)
Returns a byte array of this integer's value.
|
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.
|
short |
ToInt16Checked()
Converts this number's value to a 16-bit signed integer if it can fit in a
16-bit signed integer.
|
short |
ToInt16Unchecked()
Converts this number to a 16-bit signed integer, returning the
least-significant bits of this number's two's-complement form.
|
int |
ToInt32Checked()
Converts this object's value to a 32-bit signed integer, throwing an
exception if it can't fit.
|
int |
ToInt32Unchecked()
Converts this object's value to a 32-bit signed integer.
|
long |
ToInt64Checked()
Converts this object's value to a 64-bit signed integer, throwing an
exception if it can't fit.
|
long |
ToInt64Unchecked()
Converts this object's value to a 64-bit signed integer.
|
String |
ToRadixString(int radix)
Generates a string representing the value of this object, in the given
radix.
|
String |
toString()
Converts this object to a text string in base 10.
|
public static EInteger getOne()
public static EInteger getTen()
public static EInteger getZero()
public final boolean isEven()
true if this value is even; otherwise, false .public final boolean isPowerOfTwo()
true if this object's value is a power of two; otherwise,
false.public final boolean isZero()
true if this value is 0; otherwise, false .public final int signum()
public static EInteger FromBytes(byte[] bytes, boolean littleEndian)
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 following rules: 0x01, 0x2c and 200 as 0x00, 0xc8. (Note that the second example contains a set high bit in
0xC8, so an additional 0 is added at the start to ensure it's
interpreted as positive.)0xfe,
0x70 and -52869 as 0xff, 0x31, 0x7b. (Note that the second
example contains a cleared high bit in 0x31, 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.
.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.NullPointerException - The parameter bytes is null.public static EInteger FromInt32(int intValue)
intValue - A 32-bit signed integer.public static EInteger FromInt64(long longerValue)
longerValue - A 64-bit signed integer.public static EInteger FromRadixString(String str, int radix)
str - The parameter str is not documented yet.radix - The parameter radix is not documented yet.NullPointerException - The parameter str is null.public static EInteger FromRadixSubstring(String str, int radix, int index, int endIndex)
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.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 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.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.NullPointerException - The parameter str is null.IllegalArgumentException - The parameter index is less than 0,
endIndex is less than 0, or either is greater than the
string's length, or endIndex is less than index.NumberFormatException - The string portion is empty or in an invalid
format.public static EInteger FromString(String str)
str - A text string. 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.NullPointerException - The parameter str is null.NumberFormatException - The parameter str is in an invalid
format.public static EInteger FromSubstring(String str, int index, int endIndex)
str - A text string. 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.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.NullPointerException - The parameter str is null.IllegalArgumentException - The parameter index is less than 0,
endIndex is less than 0, or either is greater than the
string's length, or endIndex is less than index.NumberFormatException - The string portion is empty or in an invalid
format.public EInteger Abs()
public EInteger Add(EInteger bigintAugend)
bigintAugend - Another arbitrary-precision integer.NullPointerException - The parameter bigintAugend is
null.@Deprecated public int AsInt32Checked()
ArithmeticException - This object's value is too big to fit a
32-bit signed integer.@Deprecated public int AsInt32Unchecked()
"Forms of numbers") (in which case the return value might have a
different sign than this object's value).@Deprecated public long AsInt64Checked()
ArithmeticException - This object's value is too big to fit a
64-bit signed integer.@Deprecated public long AsInt64Unchecked()
"Forms of numbers") (in which case the return value might have a
different sign than this object's value).public boolean CanFitInInt32()
true if this object's value is from -2147483648 through
2147483647; otherwise, false.public boolean CanFitInInt64()
true if this object's value is from -9223372036854775808
through 9223372036854775807; otherwise, false.public int compareTo(EInteger other)
compareTo in interface Comparable<EInteger>other - The parameter other is not documented yet.public EInteger Divide(EInteger bigintDivisor)
bigintDivisor - Another arbitrary-precision integer.ArithmeticException - The parameter bigintDivisor is
zero.NullPointerException - The parameter bigintDivisor is
null.public EInteger[] DivRem(EInteger divisor)
divisor - The number to divide by.NullPointerException - The parameter divisor is null.ArithmeticException - The parameter divisor is 0.ArithmeticException - Attempted to divide by zero.public boolean equals(Object obj)
public EInteger Gcd(EInteger bigintSecond)
bigintSecond - Another arbitrary-precision integer.NullPointerException - The parameter bigintSecond is
null.public int GetDigitCount()
public int hashCode()
public int GetLowBit()
"Forms of numbers").).public EInteger GetLowBitAsEInteger()
"Forms of numbers").).public boolean GetSignedBit(int index)
"Forms of numbers") of this
object' s value.index - Zero based index of the bit to test. 0 means the least
significant bit.true if a bit is set in the two's-complement form (see
EDecimal) of this object' s value;
otherwise, false.public int GetSignedBitLength()
public boolean GetUnsignedBit(int index)
index - Zero based index of the bit to test. 0 means the least
significant bit.true if a bit is set in this number's absolute value.public EInteger GetUnsignedBitLengthAsEInteger()
public int GetUnsignedBitLength()
public EInteger Mod(EInteger divisor)
divisor - A divisor greater than 0 (the modulus).ArithmeticException - The parameter divisor is negative.NullPointerException - The parameter divisor is null.public EInteger ModPow(EInteger pow, EInteger mod)
pow - Another arbitrary-precision integer.mod - An arbitrary-precision integer. (3).NullPointerException - The parameter pow or mod is null.public EInteger Multiply(EInteger bigintMult)
bigintMult - Another arbitrary-precision integer.NullPointerException - The parameter bigintMult is
null.public EInteger Negate()
public EInteger Pow(int powerSmall)
powerSmall - The exponent to raise to.powerSmall is 0.IllegalArgumentException - The parameter powerSmall is less
than 0.public EInteger PowBigIntVar(EInteger power)
power - The exponent to raise to.power is 0.NullPointerException - The parameter power is null.IllegalArgumentException - The parameter power is less than 0.public EInteger Remainder(EInteger divisor)
divisor - Another arbitrary-precision integer.NullPointerException - The parameter divisor is null.ArithmeticException - Attempted to divide by zero.public EInteger ShiftLeft(int numberBits)
numberBits - The number of bits to shift. Can be negative, in which
case this is the same as shiftRight with the absolute value of
numberBits.public EInteger ShiftRight(int numberBits)
"Forms of numbers"). Thus, for negative values, the
arbitrary-precision integer is sign-extended.numberBits - Number of bits to shift right.public EInteger Sqrt()
public EInteger[] SqrtRem()
public EInteger Subtract(EInteger subtrahend)
subtrahend - Another arbitrary-precision integer.NullPointerException - The parameter subtrahend is
null.public byte[] ToBytes(boolean littleEndian)
"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 the FromBytes() method (with the same byte order) to
reconstruct this integer's value.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.public int ToInt32Checked()
ArithmeticException - This object's value is too big to fit a
32-bit signed integer.public int ToInt32Unchecked()
"Forms of numbers") (in which case the return value might have a
different sign than this object's value).public long ToInt64Checked()
ArithmeticException - This object's value is too big to fit a
64-bit signed integer.public long ToInt64Unchecked()
"Forms of numbers") (in which case the return value might have a
different sign than this object's value).public String ToRadixString(int radix)
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.IllegalArgumentException - The parameter "index" is less than 0,
"endIndex" is less than 0, or either is greater than the string's
length, or "endIndex" is less than "index" ; or radix is less than 2
or greater than 36.public String toString()
public byte ToByteChecked()
ArithmeticException - This value is less than 0 or greater than
255.public byte ToByteUnchecked()
public static EInteger FromByte(byte inputByte)
inputByte - The number to convert as a byte (from 0 to 255).public short ToInt16Checked()
ArithmeticException - This value is less than -32768 or greater
than 32767.public short ToInt16Unchecked()
public static EInteger FromInt16(short inputInt16)
inputInt16 - The number to convert as a 16-bit signed integer.CBOR for Java documentation, generated in 2016.