Class UInt384

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

public final class UInt384 extends Object implements UInt384Value<UInt384>
An unsigned 384-bit precision number.

This is a raw UInt384Value - a 384-bit precision unsigned number of no particular unit.

  • Field Details

    • MIN_VALUE

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

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

      public static final UInt384 ZERO
      The value 0
    • ONE

      public static final UInt384 ONE
      The value 1
  • Method Details

    • valueOf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      public UInt384 and(UInt384 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 UInt384 and(org.apache.tuweni.bytes.Bytes48 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
    • or

      public UInt384 or(UInt384 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 UInt384 or(org.apache.tuweni.bytes.Bytes48 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
    • xor

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

      public UInt384 xor(org.apache.tuweni.bytes.Bytes48 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
    • not

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

      public UInt384 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 UInt384 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(UInt384 other)
      Specified by:
      compareTo in interface Comparable<UInt384>
    • fitsInt

      public boolean fitsInt()
      Description copied from interface: UInt384Value
      Returns true if this value fits an int
      Specified by:
      fitsInt in interface UInt384Value<UInt384>
      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: UInt384Value
      Returns the value as an int.
      Specified by:
      intValue in interface UInt384Value<UInt384>
      Returns:
      This value as a java int assuming it is small enough to fit an int.
    • fitsLong

      public boolean fitsLong()
      Description copied from interface: UInt384Value
      Returns true if this value fits in a long.
      Specified by:
      fitsLong in interface UInt384Value<UInt384>
      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: UInt384Value
      Returns this value as a long.
      Specified by:
      toLong in interface UInt384Value<UInt384>
      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: UInt384Value
      Returns this value as a BigInteger.
      Specified by:
      toBigInteger in interface UInt384Value<UInt384>
      Returns:
      This value as a BigInteger.
    • toUInt384

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

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

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

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