Package org.apache.tuweni.units.bigints
Class UInt64
java.lang.Object
org.apache.tuweni.units.bigints.UInt64
- All Implemented Interfaces:
Comparable<UInt64>,UInt64Value<UInt64>
An unsigned 64-bit precision number.
This is a raw UInt64Value - a 64-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.Bytes 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 int.booleanfitsLong()Returns true if this value fits a long.static UInt64fromBytes(org.apache.tuweni.bytes.Bytes bytes) Return aUInt64containing the value described by the specified bytes.static UInt64fromHexString(String str) Parse a hexadecimal string into aUInt64.inthashCode()intintValue()Returns this value as an int.booleanisZero()Returns true if 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, UInt64 modulus) Returns a value that is((this * value) mod modulus).multiplyMod(UInt64 value, UInt64 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.Bytes 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>64</sup>)Returns a value that is(this<sup>exponent</sup> mod 2<sup>64</sup>)static UInt64random()Return aUInt64containing a random value.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 a BigIntegerorg.apache.tuweni.bytes.BytestoBytes()Returns the value as bytes.longtoLong()Returns this value as a long.org.apache.tuweni.bytes.BytesReturns the value as bytes without any leading zero bytes.toString()toUInt64()Convert this value to aUInt64.static UInt64valueOf(long value) Return aUInt64containing the specified value.static UInt64valueOf(BigInteger value) Return aUInt64containing the specified value.xor(org.apache.tuweni.bytes.Bytes 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.UInt64Value
addExact, addExact, subtractExact, subtractExact, toDecimalString, toHexString, toShortHexString
-
Field Details
-
MIN_VALUE
The minimum value of a UInt64 -
MAX_VALUE
The maximum value of a UInt64 -
ZERO
The value 0 -
ONE
The value 1
-
-
Method Details
-
valueOf
Return aUInt64containing the specified value.- Parameters:
value- The value to create aUInt64for.- Returns:
- A
UInt64containing the specified value. - Throws:
IllegalArgumentException- If the value is negative.
-
random
Return aUInt64containing a random value.- Returns:
- a
UInt64containing a random value
-
valueOf
Return aUInt64containing the specified value.- Parameters:
value- the value to create aUInt64for- Returns:
- a
UInt64containing the specified value - Throws:
IllegalArgumentException- if the value is negative or too large to be represented as a UInt64
-
fromBytes
Return aUInt64containing the value described by the specified bytes.- Parameters:
bytes- The bytes containing aUInt64.- Returns:
- A
UInt64containing the specified value. - Throws:
IllegalArgumentException- ifbytes.size() > 8.
-
fromHexString
Parse a hexadecimal string into aUInt64.- Parameters:
str- The hexadecimal string to parse, which may or may not start with "0x". That representation may contain less than 8 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 8 bytes.
-
isZero
public boolean isZero()Description copied from interface:UInt64ValueReturns true if this is 0.- Specified by:
isZeroin interfaceUInt64Value<UInt64>- Returns:
- True if this is the value 0.
-
add
Description copied from interface:UInt64ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
add
Description copied from interface:UInt64ValueReturns a value that is(this + value).- Specified by:
addin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to be added to this value.- Returns:
this + value
-
addMod
Description copied from interface:UInt64ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
addMod
Description copied from interface:UInt64ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
addMod
Description copied from interface:UInt64ValueReturns a value equivalent to((this + value) mod modulus).- Specified by:
addModin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to be added to this value.modulus- The modulus.- Returns:
(this + value) mod modulus
-
subtract
Description copied from interface:UInt64ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
subtract
Description copied from interface:UInt64ValueReturns a value that is(this - value).- Specified by:
subtractin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to be subtracted from this value.- Returns:
this - value
-
multiply
Description copied from interface:UInt64ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiply
Description copied from interface:UInt64ValueReturns a value that is(this * value).- Specified by:
multiplyin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to multiply this value by.- Returns:
this * value
-
multiplyMod
Description copied from interface:UInt64ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
multiplyMod
Description copied from interface:UInt64ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
multiplyMod
Description copied from interface:UInt64ValueReturns a value that is((this * value) mod modulus).- Specified by:
multiplyModin interfaceUInt64Value<UInt64>- Parameters:
value- The amount to multiply this value by.modulus- The modulus.- Returns:
(this * value) mod modulus
-
divide
Description copied from interface:UInt64ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt64Value<UInt64>- Parameters:
value- The amount to divide this value by.- Returns:
this / value
-
divide
Description copied from interface:UInt64ValueReturns a value that is(this / value).- Specified by:
dividein interfaceUInt64Value<UInt64>- Parameters:
value- The amount to divide this value by.- Returns:
this / value
-
pow
Description copied from interface:UInt64ValueReturns a value that is(this<sup>exponent</sup> mod 2<sup>64</sup>)This calculates an exponentiation over the modulus of
2^64.Note that
exponentis anUInt64rather than of the typeT.- Specified by:
powin interfaceUInt64Value<UInt64>- Parameters:
exponent- The exponent to which this value is to be raised.- Returns:
this<sup>exponent</sup> mod 2<sup>64</sup>
-
pow
Description copied from interface:UInt64ValueReturns a value that is(this<sup>exponent</sup> mod 2<sup>64</sup>)This calculates an exponentiation over the modulus of
2^64.- Specified by:
powin interfaceUInt64Value<UInt64>- Parameters:
exponent- The exponent to which this value is to be raised.- Returns:
this<sup>exponent</sup> mod 2<sup>64</sup>
-
mod
Description copied from interface:UInt64ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt64Value<UInt64>- Parameters:
modulus- The modulus.- Returns:
this mod modulus.
-
mod
Description copied from interface:UInt64ValueReturns a value that is(this mod modulus).- Specified by:
modin interfaceUInt64Value<UInt64>- 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
- Throws:
IllegalArgumentException- if more than 8 bytes are supplied
-
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
- Throws:
IllegalArgumentException- if more than 8 bytes are supplied
-
xor
Return a bit-wise XOR of this value and the supplied value.If this value and the supplied value are different lengths, then the shorter will be zero-padded to the left.
- Parameters:
value- the value to perform the operation with- Returns:
- the result of a bit-wise XOR
- Throws:
IllegalArgumentException- if more than 8 bytes are supplied
-
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
- Throws:
IllegalArgumentException- if more than 8 bytes are supplied
-
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<UInt64>
-
fitsInt
public boolean fitsInt()Description copied from interface:UInt64ValueReturns true if this value fits an int.- Specified by:
fitsIntin interfaceUInt64Value<UInt64>- 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:UInt64ValueReturns this value as an int.- Specified by:
intValuein interfaceUInt64Value<UInt64>- Returns:
- This value as a java
intassuming it is small enough to fit anint.
-
fitsLong
public boolean fitsLong()Description copied from interface:UInt64ValueReturns true if this value fits a long.- Specified by:
fitsLongin interfaceUInt64Value<UInt64>- 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:UInt64ValueReturns this value as a long.- Specified by:
toLongin interfaceUInt64Value<UInt64>- Returns:
- This value as a java
longassuming it is small enough to fit along.
-
toString
-
toBigInteger
Description copied from interface:UInt64ValueReturns this value as a BigInteger- Specified by:
toBigIntegerin interfaceUInt64Value<UInt64>- Returns:
- This value as a
BigInteger.
-
toUInt64
Description copied from interface:UInt64ValueConvert this value to aUInt64.- Specified by:
toUInt64in interfaceUInt64Value<UInt64>- Returns:
- This value as a
UInt64.
-
toBytes
public org.apache.tuweni.bytes.Bytes toBytes()Description copied from interface:UInt64ValueReturns the value as bytes.- Specified by:
toBytesin interfaceUInt64Value<UInt64>- Returns:
- The value as bytes.
-
toMinimalBytes
public org.apache.tuweni.bytes.Bytes toMinimalBytes()Description copied from interface:UInt64ValueReturns the value as bytes without any leading zero bytes.- Specified by:
toMinimalBytesin interfaceUInt64Value<UInt64>- Returns:
- The value as bytes without any leading zero bytes.
-
numberOfLeadingZeros
public int numberOfLeadingZeros()Description copied from interface:UInt64ValueReturns the number of zero bits preceding the highest-order ("leftmost") one-bit- Specified by:
numberOfLeadingZerosin interfaceUInt64Value<UInt64>- Returns:
- the number of zero bits preceding the highest-order ("leftmost") one-bit in the binary representation of this value, or 64 if the value is equal to zero.
-
bitLength
public int bitLength()Description copied from interface:UInt64ValueReturns the number of bits following and including the highest-order ("leftmost") one-bit- Specified by:
bitLengthin interfaceUInt64Value<UInt64>- 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.
-