Class UInt64

java.lang.Object
org.apache.tuweni.units.bigints.UInt64
All Implemented Interfaces:
Comparable<UInt64>, UInt64Value<UInt64>

public final class UInt64 extends Object implements UInt64Value<UInt64>
An unsigned 64-bit precision number.

This is a raw UInt64Value - a 64-bit precision unsigned number of no particular unit.

  • Field Details

    • MIN_VALUE

      public static final UInt64 MIN_VALUE
      The minimum value of a UInt64
    • MAX_VALUE

      public static final UInt64 MAX_VALUE
      The maximum value of a UInt64
    • ZERO

      public static final UInt64 ZERO
      The value 0
    • ONE

      public static final UInt64 ONE
      The value 1
  • Method Details

    • valueOf

      public static UInt64 valueOf(long value)
      Return a UInt64 containing the specified value.
      Parameters:
      value - The value to create a UInt64 for.
      Returns:
      A UInt64 containing the specified value.
      Throws:
      IllegalArgumentException - If the value is negative.
    • random

      public static UInt64 random()
      Return a UInt64 containing a random value.
      Returns:
      a UInt64 containing a random value
    • valueOf

      public static UInt64 valueOf(BigInteger value)
      Return a UInt64 containing the specified value.
      Parameters:
      value - the value to create a UInt64 for
      Returns:
      a UInt64 containing the specified value
      Throws:
      IllegalArgumentException - if the value is negative or too large to be represented as a UInt64
    • fromBytes

      public static UInt64 fromBytes(org.apache.tuweni.bytes.Bytes bytes)
      Return a UInt64 containing the value described by the specified bytes.
      Parameters:
      bytes - The bytes containing a UInt64.
      Returns:
      A UInt64 containing the specified value.
      Throws:
      IllegalArgumentException - if bytes.size() > 8.
    • fromHexString

      public static UInt64 fromHexString(String str)
      Parse a hexadecimal string into a UInt64.
      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 - if str does not correspond to a valid hexadecimal representation or contains more than 8 bytes.
    • isZero

      public boolean isZero()
      Description copied from interface: UInt64Value
      Returns true if this is 0.
      Specified by:
      isZero in interface UInt64Value<UInt64>
      Returns:
      True if this is the value 0.
    • add

      public UInt64 add(UInt64 value)
      Description copied from interface: UInt64Value
      Returns a value that is (this + value).
      Specified by:
      add in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • add

      public UInt64 add(long value)
      Description copied from interface: UInt64Value
      Returns a value that is (this + value).
      Specified by:
      add in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • addMod

      public UInt64 addMod(UInt64 value, UInt64 modulus)
      Description copied from interface: UInt64Value
      Returns a value equivalent to ((this + value) mod modulus).
      Specified by:
      addMod in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
    • addMod

      public UInt64 addMod(long value, UInt64 modulus)
      Description copied from interface: UInt64Value
      Returns a value equivalent to ((this + value) mod modulus).
      Specified by:
      addMod in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
    • addMod

      public UInt64 addMod(long value, long modulus)
      Description copied from interface: UInt64Value
      Returns a value equivalent to ((this + value) mod modulus).
      Specified by:
      addMod in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
    • subtract

      public UInt64 subtract(UInt64 value)
      Description copied from interface: UInt64Value
      Returns a value that is (this - value).
      Specified by:
      subtract in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • subtract

      public UInt64 subtract(long value)
      Description copied from interface: UInt64Value
      Returns a value that is (this - value).
      Specified by:
      subtract in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • multiply

      public UInt64 multiply(UInt64 value)
      Description copied from interface: UInt64Value
      Returns a value that is (this * value).
      Specified by:
      multiply in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to multiply this value by.
      Returns:
      this * value
    • multiply

      public UInt64 multiply(long value)
      Description copied from interface: UInt64Value
      Returns a value that is (this * value).
      Specified by:
      multiply in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to multiply this value by.
      Returns:
      this * value
    • multiplyMod

      public UInt64 multiplyMod(UInt64 value, UInt64 modulus)
      Description copied from interface: UInt64Value
      Returns a value that is ((this * value) mod modulus).
      Specified by:
      multiplyMod in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
    • multiplyMod

      public UInt64 multiplyMod(long value, UInt64 modulus)
      Description copied from interface: UInt64Value
      Returns a value that is ((this * value) mod modulus).
      Specified by:
      multiplyMod in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
    • multiplyMod

      public UInt64 multiplyMod(long value, long modulus)
      Description copied from interface: UInt64Value
      Returns a value that is ((this * value) mod modulus).
      Specified by:
      multiplyMod in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
    • divide

      public UInt64 divide(UInt64 value)
      Description copied from interface: UInt64Value
      Returns a value that is (this / value).
      Specified by:
      divide in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
    • divide

      public UInt64 divide(long value)
      Description copied from interface: UInt64Value
      Returns a value that is (this / value).
      Specified by:
      divide in interface UInt64Value<UInt64>
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
    • pow

      public UInt64 pow(UInt64 exponent)
      Description copied from interface: UInt64Value
      Returns 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 exponent is an UInt64 rather than of the type T.

      Specified by:
      pow in interface UInt64Value<UInt64>
      Parameters:
      exponent - The exponent to which this value is to be raised.
      Returns:
      this<sup>exponent</sup> mod 2<sup>64</sup>
    • pow

      public UInt64 pow(long exponent)
      Description copied from interface: UInt64Value
      Returns 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:
      pow in interface UInt64Value<UInt64>
      Parameters:
      exponent - The exponent to which this value is to be raised.
      Returns:
      this<sup>exponent</sup> mod 2<sup>64</sup>
    • mod

      public UInt64 mod(UInt64 modulus)
      Description copied from interface: UInt64Value
      Returns a value that is (this mod modulus).
      Specified by:
      mod in interface UInt64Value<UInt64>
      Parameters:
      modulus - The modulus.
      Returns:
      this mod modulus.
    • mod

      public UInt64 mod(long modulus)
      Description copied from interface: UInt64Value
      Returns a value that is (this mod modulus).
      Specified by:
      mod in interface UInt64Value<UInt64>
      Parameters:
      modulus - The modulus.
      Returns:
      this mod modulus.
    • and

      public UInt64 and(UInt64 value)
      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

      public UInt64 and(org.apache.tuweni.bytes.Bytes bytes)
      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

      public UInt64 or(UInt64 value)
      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

      public UInt64 or(org.apache.tuweni.bytes.Bytes bytes)
      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

      public UInt64 xor(UInt64 value)
      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

      public UInt64 xor(org.apache.tuweni.bytes.Bytes bytes)
      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

      public UInt64 not()
      Return a bit-wise NOT of this value.
      Returns:
      the result of a bit-wise NOT
    • shiftRight

      public UInt64 shiftRight(int distance)
      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

      public UInt64 shiftLeft(int distance)
      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

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(UInt64 other)
      Specified by:
      compareTo in interface Comparable<UInt64>
    • fitsInt

      public boolean fitsInt()
      Description copied from interface: UInt64Value
      Returns true if this value fits an int.
      Specified by:
      fitsInt in interface UInt64Value<UInt64>
      Returns:
      True if this value fits a java int (i.e. is less or equal to Integer.MAX_VALUE).
    • intValue

      public int intValue()
      Description copied from interface: UInt64Value
      Returns this value as an int.
      Specified by:
      intValue in interface UInt64Value<UInt64>
      Returns:
      This value as a java int assuming it is small enough to fit an int.
    • fitsLong

      public boolean fitsLong()
      Description copied from interface: UInt64Value
      Returns true if this value fits a long.
      Specified by:
      fitsLong in interface UInt64Value<UInt64>
      Returns:
      True if this value fits a java long (i.e. is less or equal to Long.MAX_VALUE).
    • toLong

      public long toLong()
      Description copied from interface: UInt64Value
      Returns this value as a long.
      Specified by:
      toLong in interface UInt64Value<UInt64>
      Returns:
      This value as a java long assuming it is small enough to fit a long.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toBigInteger

      public BigInteger toBigInteger()
      Description copied from interface: UInt64Value
      Returns this value as a BigInteger
      Specified by:
      toBigInteger in interface UInt64Value<UInt64>
      Returns:
      This value as a BigInteger.
    • toUInt64

      public UInt64 toUInt64()
      Description copied from interface: UInt64Value
      Convert this value to a UInt64.
      Specified by:
      toUInt64 in interface UInt64Value<UInt64>
      Returns:
      This value as a UInt64.
    • toBytes

      public org.apache.tuweni.bytes.Bytes toBytes()
      Description copied from interface: UInt64Value
      Returns the value as bytes.
      Specified by:
      toBytes in interface UInt64Value<UInt64>
      Returns:
      The value as bytes.
    • toMinimalBytes

      public org.apache.tuweni.bytes.Bytes toMinimalBytes()
      Description copied from interface: UInt64Value
      Returns the value as bytes without any leading zero bytes.
      Specified by:
      toMinimalBytes in interface UInt64Value<UInt64>
      Returns:
      The value as bytes without any leading zero bytes.
    • numberOfLeadingZeros

      public int numberOfLeadingZeros()
      Description copied from interface: UInt64Value
      Returns the number of zero bits preceding the highest-order ("leftmost") one-bit
      Specified by:
      numberOfLeadingZeros in interface UInt64Value<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: UInt64Value
      Returns the number of bits following and including the highest-order ("leftmost") one-bit
      Specified by:
      bitLength in interface UInt64Value<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.