tuweni / org.apache.tuweni.units.bigints / UInt256Value

UInt256Value

interface UInt256Value<T : UInt256Value<T>!> : Comparable<T> (source)

Represents a 256-bit (32 bytes) unsigned integer value.

A UInt256Value is an unsigned integer value stored with 32 bytes, so whose value can range between 0 and 2^256-1.

This interface defines operations for value types with a 256-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 UInt256Value types.

Where only a pure numerical 256-bit value is required, UInt256 should be used.

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

Functions

add

Returns a value that is (this + value).

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

addExact

Returns a value that is (this + value).

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

addMod

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

abstract fun addMod(value: T, modulus: UInt256!): T
abstract fun addMod(value: Long, modulus: UInt256!): T
abstract fun addMod(value: Long, modulus: Long): T

bitLength

Provides 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.

open fun bitLength(): Int

divide

Returns a value that is (this / value).

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

divideCeil

Returns a value that is ceiling(this / value).

abstract fun divideCeil(value: T): T
abstract fun divideCeil(value: Long): T

fitsInt

Returns true if the value can fit in an int.

open fun fitsInt(): Boolean

fitsLong

Returns true if the value can fit in a long.

open fun fitsLong(): Boolean

intValue

Provides this value as an int.

open fun intValue(): Int

isZero

Returns true is the value is 0.

open fun isZero(): Boolean

mod

Returns a value that is (this mod modulus).

abstract fun mod(modulus: UInt256!): T
abstract fun mod(modulus: Long): T

mod0

Returns a value that is (this mod modulus), or 0 if modulus is 0.

abstract fun mod0(modulus: UInt256!): T
abstract fun mod0(modulus: Long): T

multiply

Returns a value that is (this * value).

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

multiplyMod

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

abstract fun multiplyMod(value: T, modulus: UInt256!): T
abstract fun multiplyMod(value: Long, modulus: UInt256!): T
abstract fun multiplyMod(value: Long, modulus: Long): T

numberOfLeadingZeros

Provides the number of zero bits preceding the highest-order one-bit.

open fun numberOfLeadingZeros(): Int

plus

Returns a value that is (this + value).

open fun plus(value: T): T
open fun plus(value: Long): T

pow

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

abstract fun pow(exponent: UInt256!): T
abstract fun pow(exponent: Long): T

subtract

Returns a value that is (this - value).

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

subtractExact

Returns a value that is (this - value).

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

toBigInteger

Provides the value as a BigInteger.

open fun toBigInteger(): BigInteger!

toBytes

Provides the value as bytes.

abstract fun toBytes(): Bytes32!

toHexString

This value represented as an hexadecimal string.

open fun toHexString(): String!

toLong

Provides the value as a long.

open fun toLong(): Long

toMinimalBytes

Provides the value as bytes without any leading zero bytes.

abstract fun toMinimalBytes(): Bytes!

toShortHexString

Returns this value represented as a minimal hexadecimal string (without any leading zero)

open fun toShortHexString(): String!

toUInt256

Convert this value to a UInt256.

abstract fun toUInt256(): UInt256!

Inheritors

BaseUInt256Value

Base class for UInt256Value.

abstract class BaseUInt256Value<T : UInt256Value<T>!> : UInt256Value<T>

UInt256

An unsigned 256-bit precision number. This is a raw UInt256Value - a 256-bit precision unsigned number of no particular unit.

class UInt256 : UInt256Value<UInt256!>