Uints
are immutable, so all operations create a new object as the result of the operation.
Since these are bound integers, they will overflow and underflow if the operation returns a value outside the boundaries - for a Uint256
, 0 to 2^256.
For this reason, the API also contains exact
methods that throw exceptions if the operations overflows or underflows.
Additionally, the method divideCeil(other)
divides integers but returns the ceiling of the rounding.
{%highlight java%} UInt256 result = UInt256.valueOf(12L).divide(UInt256.valueOf(5L)); // returns 2 UInt256 resultCeiling = UInt256.valueOf(12L).divideCeil(UInt256.valueOf(5L)); // returns 3 {%endhighlight%}
You can use the method mod(divisor)
to get the modulus of the value by the divisor.
The method mod0
is more forgiving - if you divide by zero, it will return zero instead of throwing an exception.
The method pow(exponent)
returns a value that is `value^exponent mod 2^256.
You can use the following methods to perform boolean operations:
not()
: bit-wise NOT of this value.and(other)
: bit-wise AND of this value and the supplied value.or(other)
: bit-wise OR of this value and the supplied value.xor(other)
: bit-wise XOR of this value and the supplied value.You can shift right and left the bits of the underlying bytes object by a given distance.
This is equivalent to the <<<
or >>>
operators in Java.