Uints
are immutable, so all operations create a new object as the result of the operation.
Arithmetic operations
Adding and subtracting
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.
Multiplying and dividing
Additionally, the method divideCeil(other)
divides integers but returns the ceiling of the rounding.
Modulus
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.
Power
The method pow(exponent)
returns a value that is `value^exponent mod 2^256.
Boolean operations
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.
Shifting bytes
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.