tuweni / org.apache.tuweni.units.bigints / UInt32Value

UInt32Value

interface UInt32Value<T : UInt32Value<T>> : Comparable<T> (source)

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.

Parameters

- The concrete type of the value.

Functions

add

abstract fun add(value: T): T
abstract fun add(value: Int): T

Returns a value that is (this + value).

addExact

open fun addExact(value: T): T
open fun addExact(value: Int): T

Returns a value that is (this + value).

addMod

abstract fun addMod(value: T, modulus: UInt32): T
abstract fun addMod(value: Long, modulus: UInt32): T
abstract fun addMod(value: Long, modulus: Long): T

Returns a value equivalent to ((this + value) mod modulus).

bitLength

open fun bitLength(): Int

divide

abstract fun divide(value: T): T
abstract fun divide(value: Int): T

Returns a value that is (this / value).

fitsInt

open fun fitsInt(): Boolean

fitsLong

open fun fitsLong(): Boolean

intValue

open fun intValue(): Int

isZero

open fun isZero(): Boolean

mod

abstract fun mod(modulus: UInt32): T
abstract fun mod(modulus: Int): T

Returns a value that is (this mod modulus).

multiply

abstract fun multiply(value: T): T
abstract fun multiply(value: Int): T

Returns a value that is (this * value).

multiplyMod

abstract fun multiplyMod(value: T, modulus: UInt32): T
abstract fun multiplyMod(value: Int, modulus: UInt32): T
abstract fun multiplyMod(value: Int, modulus: Int): T

Returns a value that is ((this * value) mod modulus).

numberOfLeadingZeros

open fun numberOfLeadingZeros(): Int

pow

abstract fun pow(exponent: UInt32): T

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.

abstract fun pow(exponent: Long): T

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

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

subtract

abstract fun subtract(value: T): T
abstract fun subtract(value: Int): T

Returns a value that is (this - value).

subtractExact

open fun subtractExact(value: T): T
open fun subtractExact(value: Int): T

Returns a value that is (this - value).

toBigInteger

open fun toBigInteger(): BigInteger

toBytes

abstract fun toBytes(): Bytes

toHexString

open fun toHexString(): String

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.

toLong

open fun toLong(): Long

toMinimalBytes

abstract fun toMinimalBytes(): Bytes

toShortHexString

open fun toShortHexString(): String

toUInt32

abstract fun toUInt32(): UInt32

Convert this value to a UInt32.

Inheritors

BaseUInt32Value

abstract class BaseUInt32Value<T : UInt32Value<T>> : UInt32Value<T>

Base class for UInt32Value.

This class is abstract as it is not meant to be used directly, but it has no abstract methods. As mentioned in UInt32Value, this is used to create strongly-typed type aliases of UInt32. In other words, this allow to "tag" numbers with the unit of what they represent for the type-system, which can help clarity, but also forbid mixing numbers that are mean to be of different units (the strongly-typed part).

This class implements UInt32Value, but also adds a few operations that take a UInt32 directly, for instance #multiply(UInt32). The rational is that multiplying a given quantity of something by a "raw" number is always meaningful, and return a new quantity of the same thing.

UInt32

class UInt32 : UInt32Value<UInt32>

An unsigned 32-bit precision number. This is a raw UInt32Value - a 32-bit precision unsigned number of no particular unit.