Interface UInt32Value<T extends UInt32Value<T>>

Type Parameters:
T - The concrete type of the value.
All Superinterfaces:
Comparable<T>
All Known Implementing Classes:
BaseUInt32Value, UInt32

public interface UInt32Value<T extends UInt32Value<T>> extends Comparable<T>
Represents a 32-bit (8 bytes) unsigned integer value.

A UInt32Value is an unsigned integer value whose value can range between 0 and 2^32-1.

This interface defines operations for value types with a 32-bit precision range. The methods provided by this interface take parameters of the same type (and also long. This provides type safety by ensuring calculations cannot mix different UInt32Value types.

Where only a pure numerical 32-bit value is required, UInt32 should be used.

It is strongly advised to extend BaseUInt32Value rather than implementing this interface directly. Doing so provides type safety in that quantities of different units cannot be mixed accidentally.

  • Method Summary

    Modifier and Type
    Method
    Description
    add(int value)
    Returns a value that is (this + value).
    add(T value)
    Returns a value that is (this + value).
    default T
    addExact(int value)
    Returns a value that is (this + value).
    default T
    addExact(T value)
    Returns a value that is (this + value).
    addMod(long value, long modulus)
    Returns a value equivalent to ((this + value) mod modulus).
    addMod(long value, UInt32 modulus)
    Returns a value equivalent to ((this + value) mod modulus).
    addMod(T value, UInt32 modulus)
    Returns a value equivalent to ((this + value) mod modulus).
    default int
    Provides the number of bits following and including the highest-order ("leftmost") one-bit
    divide(int value)
    Returns a value that is (this / value).
    divide(T value)
    Returns a value that is (this / value).
    default boolean
    Returns true if this value fits an int.
    default boolean
    Returns true if this value fits a long.
    default int
    Returns this value as an int.
    default boolean
    Returns true is this is 0.
    mod(int modulus)
    Returns a value that is (this mod modulus).
    mod(UInt32 modulus)
    Returns a value that is (this mod modulus).
    multiply(int value)
    Returns a value that is (this * value).
    multiply(T value)
    Returns a value that is (this * value).
    multiplyMod(int value, int modulus)
    Returns a value that is ((this * value) mod modulus).
    multiplyMod(int value, UInt32 modulus)
    Returns a value that is ((this * value) mod modulus).
    multiplyMod(T value, UInt32 modulus)
    Returns a value that is ((this * value) mod modulus).
    default int
    Provides the number of zero bits preceding the highest-order ("leftmost") one-bit
    pow(long exponent)
    Returns a value that is (this<sup>exponent</sup> mod 2<sup>32</sup>)
    pow(UInt32 exponent)
    Returns a value that is (this<sup>exponent</sup> mod 2<sup>32</sup>)
    subtract(int value)
    Returns a value that is (this - value).
    subtract(T value)
    Returns a value that is (this - value).
    default T
    subtractExact(int value)
    Returns a value that is (this - value).
    default T
    Returns a value that is (this - value).
    default BigInteger
    Provides this value as a BigInteger.
    org.apache.tuweni.bytes.Bytes
    Provides the value as bytes.
    default String
    Returns the decimal representation of this value as a String.
    default String
    This value represented as an hexadecimal string.
    default long
    Returns this value as a long.
    org.apache.tuweni.bytes.Bytes
    Provides the value as bytes without any leading zero bytes
    default String
    Returns this value represented as a minimal hexadecimal string (without any leading zero).
    Convert this value to a UInt32.

    Methods inherited from interface java.lang.Comparable

    compareTo
  • Method Details

    • isZero

      default boolean isZero()
      Returns true is this is 0.
      Returns:
      True if this is the value 0.
    • add

      T add(T value)
      Returns a value that is (this + value).
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • addExact

      default T addExact(T value)
      Returns a value that is (this + value).
      Parameters:
      value - the amount to be added to this value
      Returns:
      this + value
      Throws:
      ArithmeticException - if the result of the addition overflows
    • add

      T add(int value)
      Returns a value that is (this + value).
      Parameters:
      value - The amount to be added to this value.
      Returns:
      this + value
    • addExact

      default T addExact(int value)
      Returns a value that is (this + value).
      Parameters:
      value - the amount to be added to this value
      Returns:
      this + value
      Throws:
      ArithmeticException - if the result of the addition overflows
    • addMod

      T addMod(T value, UInt32 modulus)
      Returns a value equivalent to ((this + value) mod modulus).
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
      Throws:
      ArithmeticException - modulus == 0.
    • addMod

      T addMod(long value, UInt32 modulus)
      Returns a value equivalent to ((this + value) mod modulus).
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
      Throws:
      ArithmeticException - modulus == 0.
    • addMod

      T addMod(long value, long modulus)
      Returns a value equivalent to ((this + value) mod modulus).
      Parameters:
      value - The amount to be added to this value.
      modulus - The modulus.
      Returns:
      (this + value) mod modulus
      Throws:
      ArithmeticException - modulus ≤ 0.
    • subtract

      T subtract(T value)
      Returns a value that is (this - value).
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • subtractExact

      default T subtractExact(T value)
      Returns a value that is (this - value).
      Parameters:
      value - the amount to be subtracted to this value
      Returns:
      this - value
      Throws:
      ArithmeticException - if the result of the subtraction overflows
    • subtract

      T subtract(int value)
      Returns a value that is (this - value).
      Parameters:
      value - The amount to be subtracted from this value.
      Returns:
      this - value
    • subtractExact

      default T subtractExact(int value)
      Returns a value that is (this - value).
      Parameters:
      value - the amount to be subtracted to this value
      Returns:
      this - value
      Throws:
      ArithmeticException - if the result of the subtraction overflows
    • multiply

      T multiply(T value)
      Returns a value that is (this * value).
      Parameters:
      value - The amount to multiply this value by.
      Returns:
      this * value
    • multiply

      T multiply(int value)
      Returns a value that is (this * value).
      Parameters:
      value - The amount to multiply this value by.
      Returns:
      this * value
      Throws:
      ArithmeticException - value < 0.
    • multiplyMod

      T multiplyMod(T value, UInt32 modulus)
      Returns a value that is ((this * value) mod modulus).
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
      Throws:
      ArithmeticException - value < 0 or modulus == 0.
    • multiplyMod

      T multiplyMod(int value, UInt32 modulus)
      Returns a value that is ((this * value) mod modulus).
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
      Throws:
      ArithmeticException - value < 0 or modulus == 0.
    • multiplyMod

      T multiplyMod(int value, int modulus)
      Returns a value that is ((this * value) mod modulus).
      Parameters:
      value - The amount to multiply this value by.
      modulus - The modulus.
      Returns:
      (this * value) mod modulus
      Throws:
      ArithmeticException - value < 0 or modulus ≤ 0.
    • divide

      T divide(T value)
      Returns a value that is (this / value).
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
      Throws:
      ArithmeticException - value == 0.
    • divide

      T divide(int value)
      Returns a value that is (this / value).
      Parameters:
      value - The amount to divide this value by.
      Returns:
      this / value
      Throws:
      ArithmeticException - value ≤ 0.
    • pow

      T pow(UInt32 exponent)
      Returns a value that is (this<sup>exponent</sup> mod 2<sup>32</sup>)

      This calculates an exponentiation over the modulus of 2^32.

      Note that exponent is an UInt32 rather than of the type T.

      Parameters:
      exponent - The exponent to which this value is to be raised.
      Returns:
      this<sup>exponent</sup> mod 2<sup>32</sup>
    • pow

      T pow(long exponent)
      Returns a value that is (this<sup>exponent</sup> mod 2<sup>32</sup>)

      This calculates an exponentiation over the modulus of 2^32.

      Parameters:
      exponent - The exponent to which this value is to be raised.
      Returns:
      this<sup>exponent</sup> mod 2<sup>32</sup>
    • mod

      T mod(UInt32 modulus)
      Returns a value that is (this mod modulus).
      Parameters:
      modulus - The modulus.
      Returns:
      this mod modulus.
      Throws:
      ArithmeticException - modulus == 0.
    • mod

      T mod(int modulus)
      Returns a value that is (this mod modulus).
      Parameters:
      modulus - The modulus.
      Returns:
      this mod modulus.
      Throws:
      ArithmeticException - modulus ≤ 0.
    • fitsInt

      default boolean fitsInt()
      Returns true if this value fits an int.
      Returns:
      True if this value fits a java int (i.e. is less or equal to Integer.MAX_VALUE).
    • intValue

      default int intValue()
      Returns this value as an int.
      Returns:
      This value as a java int assuming it is small enough to fit an int.
      Throws:
      ArithmeticException - If the value does not fit an int, that is if !fitsInt().
    • fitsLong

      default boolean fitsLong()
      Returns true if this value fits a long.
      Returns:
      True if this value fits a java long (i.e. is less or equal to Long.MAX_VALUE).
    • toLong

      default long toLong()
      Returns this value as a long.
      Returns:
      This value as a java long assuming it is small enough to fit a long.
      Throws:
      ArithmeticException - If the value does not fit a long, that is if !fitsLong().
    • toBigInteger

      default BigInteger toBigInteger()
      Provides this value as a BigInteger.
      Returns:
      This value as a BigInteger.
    • toHexString

      default String toHexString()
      This value represented as an hexadecimal string.

      Note that this representation includes all the 8 underlying bytes, no matter what the integer actually represents (in other words, it can have many leading zeros). For a shorter representation that don't include leading zeros, use toShortHexString().

      Returns:
      This value represented as an hexadecimal string.
    • toShortHexString

      default String toShortHexString()
      Returns this value represented as a minimal hexadecimal string (without any leading zero).
      Returns:
      This value represented as a minimal hexadecimal string (without any leading zero).
    • toUInt32

      UInt32 toUInt32()
      Convert this value to a UInt32.
      Returns:
      This value as a UInt32.
    • toBytes

      org.apache.tuweni.bytes.Bytes toBytes()
      Provides the value as bytes.
      Returns:
      The value as bytes.
    • toMinimalBytes

      org.apache.tuweni.bytes.Bytes toMinimalBytes()
      Provides the value as bytes without any leading zero bytes
      Returns:
      The value as bytes without any leading zero bytes.
    • numberOfLeadingZeros

      default int numberOfLeadingZeros()
      Provides the number of zero bits preceding the highest-order ("leftmost") one-bit
      Returns:
      the number of zero bits preceding the highest-order ("leftmost") one-bit in the binary representation of this value, or 32 if the value is equal to zero.
    • bitLength

      default int bitLength()
      Provides the number of bits following and including the highest-order ("leftmost") one-bit
      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.
    • toDecimalString

      default String toDecimalString()
      Returns the decimal representation of this value as a String.
      Returns:
      the decimal representation of this value as a String.