Package org.apache.tuweni.units.bigints
Class UInt384
java.lang.Object
org.apache.tuweni.units.bigints.UInt384
- All Implemented Interfaces:
Comparable<UInt384>,UInt384Value<UInt384>
An unsigned 384-bit precision number.
This is a raw UInt384Value - a 384-bit precision unsigned number of no particular
unit.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionadd(long value) Returns a value that is(this + value).Returns a value that is(this + value).addMod(long value, long modulus) Returns a value equivalent to((this + value) mod modulus).Returns a value equivalent to((this + value) mod modulus).Returns a value equivalent to((this + value) mod modulus).and(org.apache.tuweni.bytes.Bytes48 bytes) Return a bit-wise AND of this value and the supplied bytes.Return a bit-wise AND of this value and the supplied value.intReturns the number of bits following and including the highest-order ("leftmost") one-bitintdivide(long value) Returns a value that is(this / value).Returns a value that is(this / value).booleanbooleanfitsInt()Returns true if this value fits an intbooleanfitsLong()Returns true if this value fits in a long.static UInt384fromBytes(org.apache.tuweni.bytes.Bytes bytes) Return aUInt384containing the value described by the specified bytes.static UInt384fromHexString(String str) Parse a hexadecimal string into aUInt384.inthashCode()intintValue()Returns the value as an int.booleanisZero()Returns true is this is 0.mod(long modulus) Returns a value that is(this mod modulus).Returns a value that is(this mod modulus).multiply(long value) Returns a value that is(this * value).Returns a value that is(this * value).multiplyMod(long value, long modulus) Returns a value that is((this * value) mod modulus).multiplyMod(long value, UInt384 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(UInt384 value, UInt384 modulus) Returns a value that is((this * value) mod modulus).not()Return a bit-wise NOT of this value.intReturns the number of zero bits preceding the highest-order ("leftmost") one-bitor(org.apache.tuweni.bytes.Bytes48 bytes) Return a bit-wise OR of this value and the supplied bytes.Return a bit-wise OR of this value and the supplied value.pow(long exponent) Returns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)Returns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)shiftLeft(int distance) Shift all bits in this value to the left.shiftRight(int distance) Shift all bits in this value to the right.subtract(long value) Returns a value that is(this - value).Returns a value that is(this - value).Returns this value as aBigInteger.org.apache.tuweni.bytes.Bytes48toBytes()Returns the value as byteslongtoLong()Returns this value as a long.org.apache.tuweni.bytes.BytesRetuns the value as bytes without any leading zero bytes.toString()Convert this value to aUInt384.static UInt384valueOf(long value) Return aUInt384containing the specified value.static UInt384valueOf(BigInteger value) Return aUInt384containing the specified value.xor(org.apache.tuweni.bytes.Bytes48 bytes) Return a bit-wise XOR of this value and the supplied bytes.Return a bit-wise XOR of this value and the supplied value.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.tuweni.units.bigints.UInt384Value
addExact, addExact, subtractExact, subtractExact, toDecimalString, toHexString, toShortHexString
-
Field Details
-
MIN_VALUE
The minimum value of a UInt384 -
MAX_VALUE
The maximum value of a UInt384 -
ZERO
The value 0 -
ONE
The value 1
-
-
Method Details
-
valueOf
Return aUInt384containing the specified value.- Parameters:
value- The value to create aUInt384for.- Returns:
- A
UInt384containing the specified value. - Throws:
IllegalArgumentException- If the value is negative.
-
valueOf
Return aUInt384containing the specified value.- Parameters:
value- the value to create aUInt384for- Returns:
- a
UInt384containing the specified value - Throws:
IllegalArgumentException- if the value is negative or too large to be represented as a UInt384
-
fromBytes
Return aUInt384containing the value described by the specified bytes.- Parameters:
bytes- The bytes containing aUInt384.- Returns:
- A
UInt384containing the specified value. - Throws:
IllegalArgumentException- ifbytes.size() > 48.
-
fromHexString
Parse a hexadecimal string into aUInt384.- Parameters:
str- The hexadecimal string to parse, which may or may not start with "0x". That representation may contain less than 48 bytes, in which case the result is left padded with zeros.- Returns:
- The value corresponding to
str. - Throws:
IllegalArgumentException- ifstrdoes not correspond to a valid hexadecimal representation or contains more than 48 bytes.
-
isZero
public boolean isZero()Description copied from interface:UInt384ValueReturns true is this is 0.- Specified by:
isZeroin interfaceUInt384Value<UInt384>- Returns:
- True if this is the value 0.
-
add
Description copied from interface:UInt384ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
add
Description copied from interface:UInt384ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
addMod
Description copied from interface:UInt384ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
addMod
Description copied from interface:UInt384ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
addMod
Description copied from interface:UInt384ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
subtract
Description copied from interface:UInt384ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
subtract
Description copied from interface:UInt384ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
multiply
Description copied from interface:UInt384ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiply
Description copied from interface:UInt384ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiplyMod
Description copied from interface:UInt384ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
multiplyMod
Description copied from interface:UInt384ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
multiplyMod
Description copied from interface:UInt384ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt384Value<UInt384>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
divide
Description copied from interface:UInt384ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt384Value<UInt384>- Parameters:
value- The amount to divide this value by.- Returns:
this / value
-
divide
Description copied from interface:UInt384ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt384Value<UInt384>- Parameters:
value- The amount to divide this value by.- Returns:
this / value
-
pow
Description copied from interface:UInt384ValueReturns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)This calculates an exponentiation over the modulus of
2^384.Note that
exponentis anUInt384rather than of the typeT.- Specified by:
powin interfaceUInt384Value<UInt384>- Parameters:
exponent- The exponent to which this value is to be raised.- Returns:
this<sup>exponent</sup> mod 2<sup>384</sup>
-
pow
Description copied from interface:UInt384ValueReturns a value that is(this<sup>exponent</sup> mod 2<sup>384</sup>)This calculates an exponentiation over the modulus of
2^384.- Specified by:
powin interfaceUInt384Value<UInt384>- Parameters:
exponent- The exponent to which this value is to be raised.- Returns:
this<sup>exponent</sup> mod 2<sup>384</sup>
-
mod
Description copied from interface:UInt384ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt384Value<UInt384>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
mod
Description copied from interface:UInt384ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt384Value<UInt384>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
and
Return a bit-wise AND of this value and the supplied value.- Parameters:
value- the value to perform the operation with- Returns:
- the result of a bit-wise AND
-
and
Return a bit-wise AND of this value and the supplied bytes.- Parameters:
bytes- the bytes to perform the operation with- Returns:
- the result of a bit-wise AND
-
or
Return a bit-wise OR of this value and the supplied value.- Parameters:
value- the value to perform the operation with- Returns:
- the result of a bit-wise OR
-
or
Return a bit-wise OR of this value and the supplied bytes.- Parameters:
bytes- the bytes to perform the operation with- Returns:
- the result of a bit-wise OR
-
xor
Return a bit-wise XOR of this value and the supplied value.- Parameters:
value- the value to perform the operation with- Returns:
- the result of a bit-wise XOR
-
xor
Return a bit-wise XOR of this value and the supplied bytes.- Parameters:
bytes- the bytes to perform the operation with- Returns:
- the result of a bit-wise XOR
-
not
Return a bit-wise NOT of this value.- Returns:
- the result of a bit-wise NOT
-
shiftRight
Shift all bits in this value to the right.- Parameters:
distance- The number of bits to shift by.- Returns:
- A value containing the shifted bits.
-
shiftLeft
Shift all bits in this value to the left.- Parameters:
distance- The number of bits to shift by.- Returns:
- A value containing the shifted bits.
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<UInt384>
-
fitsInt
public boolean fitsInt()Description copied from interface:UInt384ValueReturns true if this value fits an int- Specified by:
fitsIntin interfaceUInt384Value<UInt384>- Returns:
- True if this value fits a java
int(i.e. is less or equal toInteger.MAX_VALUE).
-
intValue
public int intValue()Description copied from interface:UInt384ValueReturns the value as an int.- Specified by:
intValuein interfaceUInt384Value<UInt384>- Returns:
- This value as a java
intassuming it is small enough to fit anint.
-
fitsLong
public boolean fitsLong()Description copied from interface:UInt384ValueReturns true if this value fits in a long.- Specified by:
fitsLongin interfaceUInt384Value<UInt384>- Returns:
- True if this value fits a java
long(i.e. is less or equal toLong.MAX_VALUE).
-
toLong
public long toLong()Description copied from interface:UInt384ValueReturns this value as a long.- Specified by:
toLongin interfaceUInt384Value<UInt384>- Returns:
- This value as a java
longassuming it is small enough to fit along.
-
toString
-
toBigInteger
Description copied from interface:UInt384ValueReturns this value as aBigInteger.- Specified by:
toBigIntegerin interfaceUInt384Value<UInt384>- Returns:
- This value as a
BigInteger.
-
toUInt384
Description copied from interface:UInt384ValueConvert this value to aUInt384.- Specified by:
toUInt384in interfaceUInt384Value<UInt384>- Returns:
- This value as a
UInt384.
-
toBytes
public org.apache.tuweni.bytes.Bytes48 toBytes()Description copied from interface:UInt384ValueReturns the value as bytes- Specified by:
toBytesin interfaceUInt384Value<UInt384>- Returns:
- The value as bytes.
-
toMinimalBytes
public org.apache.tuweni.bytes.Bytes toMinimalBytes()Description copied from interface:UInt384ValueRetuns the value as bytes without any leading zero bytes.- Specified by:
toMinimalBytesin interfaceUInt384Value<UInt384>- Returns:
- The value as bytes without any leading zero bytes.
-
numberOfLeadingZeros
public int numberOfLeadingZeros()Description copied from interface:UInt384ValueReturns the number of zero bits preceding the highest-order ("leftmost") one-bit- Specified by:
numberOfLeadingZerosin interfaceUInt384Value<UInt384>- Returns:
- the number of zero bits preceding the highest-order ("leftmost") one-bit in the binary representation of this value, or 384 if the value is equal to zero.
-
bitLength
public int bitLength()Description copied from interface:UInt384ValueReturns the number of bits following and including the highest-order ("leftmost") one-bit- Specified by:
bitLengthin interfaceUInt384Value<UInt384>- Returns:
- The number of bits following and including the highest-order ("leftmost") one-bit in the binary representation of this value, or zero if all bits are zero.
-