Modifier and Type | Field and Description |
---|---|
static int |
BYTES
Size of this numeric type in bytes.
|
static UInt256 |
EIGHT |
static UInt256 |
FIVE |
static UInt256 |
FOUR |
static UInt256 |
MAX_VALUE
A constant holding the maximum value an
Int256 can
have, 2255-1. |
static UInt256 |
MIN_VALUE
A constant holding the minimum value an
Int256 can
have, -2255. |
static UInt256 |
NINE |
static UInt256 |
ONE |
static UInt256 |
SEVEN |
static UInt256 |
SIX |
static int |
SIZE
Size of this numeric type in bits.
|
static UInt256 |
TEN |
static UInt256 |
THREE |
static UInt256 |
TWO |
static UInt256 |
ZERO |
Modifier and Type | Method and Description |
---|---|
UInt256 |
add(UInt256 other)
Adds
other to this , returning the result. |
UInt256 |
and(UInt256 other)
Calculates the bitwise and of
this with other
(this & other ). |
int |
compareTo(UInt256 n) |
UInt256 |
decrement()
Decrements
this . |
UInt256 |
divide(UInt256 divisor)
Divides
this by the specified divisor. |
boolean |
equals(java.lang.Object obj) |
static UInt256 |
from(byte[] bytes)
Factory method for materialising an
UInt256 from an array
of bytes. |
static UInt256 |
from(byte[] bytes,
int offset)
Factory method for materialising an
UInt256 from an array
of bytes. |
static UInt256 |
from(int value)
Factory method for materialising an
UInt256 from an int value. |
static UInt256 |
from(Int128 value)
|
static UInt256 |
from(Int128 high,
Int128 low)
|
static UInt256 |
from(long value)
Factory method for materialising an
UInt256 from a long value. |
static UInt256 |
from(short value)
Factory method for materialising an
UInt256 from a short
value. |
static UInt256 |
from(java.lang.String s)
Factory method for materialising an
UInt256 from a string. |
Int128 |
getHigh()
Returns the most significant word.
|
Int128 |
getLow()
Returns the least significant word.
|
int |
hashCode() |
UInt256 |
increment()
Increments
this . |
UInt256 |
invert()
Returns the value of
~this . |
boolean |
isEven()
Returns
true if this is an even number. |
boolean |
isOdd()
Returns
true if this is an odd number. |
boolean |
isZero()
Returns
true if this is zero. |
UInt256 |
multiply(UInt256 multiplicand)
Multiplies
this by the specified multiplicand. |
int |
numberOfLeadingZeros()
Returns the number of zero bits preceding the highest-order
("leftmost") one-bit in the two's complement binary representation
of the specified
long value. |
UInt256 |
or(UInt256 other)
Calculates the bitwise inclusive-or of
this with other
(this | other ). |
UInt256 |
pow(int exp)
Calculates
this exp . |
UInt256 |
remainder(UInt256 divisor)
Returns the remainder of the division of
this by
the specified divisor. |
UInt256 |
shiftLeft()
Shifts
this left 1 bit. |
UInt256 |
shiftRight()
Shifts
this right 1 bit. |
UInt256 |
subtract(UInt256 other)
Subtracts
other from this , returning the result. |
byte[] |
toByteArray()
Converts
this to an array of bytes. |
byte[] |
toByteArray(byte[] bytes,
int offset)
Converts
this to an array of bytes. |
java.lang.String |
toString() |
java.lang.String |
toString(int radix)
Returns a string representation of this object in the specified radix.
|
UInt256 |
xor(UInt256 other)
Calculates the exclusive-or of
this with other
(this ^ other ). |
public static final int SIZE
public static final int BYTES
public static final UInt256 MIN_VALUE
Int256
can
have, -2255.public static final UInt256 MAX_VALUE
Int256
can
have, 2255-1.public static final UInt256 ZERO
public static final UInt256 ONE
public static final UInt256 TWO
public static final UInt256 THREE
public static final UInt256 FOUR
public static final UInt256 FIVE
public static final UInt256 SIX
public static final UInt256 SEVEN
public static final UInt256 EIGHT
public static final UInt256 NINE
public static final UInt256 TEN
public static UInt256 from(short value)
UInt256
from a short
value.public static UInt256 from(int value)
UInt256
from an int
value.public static UInt256 from(long value)
UInt256
from a long
value.
Note that values are sign extended into the 256 bit value.public static UInt256 from(Int128 value)
value
- The least significant word of the value.UInt256
type.java.lang.IllegalArgumentException
- if value
is negativepublic static UInt256 from(Int128 high, Int128 low)
UInt256
from an Int128
value.
Note that the value of high
is treated as an unsigned value.
high
- The most significant word of the value.low
- The least significant word of the value.UInt256
type.public static UInt256 from(byte[] bytes)
UInt256
from an array
of bytes. The array is most-significant byte first, and must not be
zero length.
If the array is smaller than BYTES
, then it is effectively
padded with leading bytes with the correct sign.
If the array is longer than BYTES
, then values at index
BYTES
and beyond are ignored.
bytes
- The array of bytes to be used.bytes
as an UInt256
type.java.lang.IllegalArgumentException
- if bytes
is 0 length.toByteArray()
public static UInt256 from(byte[] bytes, int offset)
UInt256
from an array
of bytes. The array is most-significant byte first.bytes
- The array of bytes to be used.offset
- The offset within the array to be used.bytes
from offset
as an UInt256
type.toByteArray()
public static UInt256 from(java.lang.String s)
UInt256
from a string.
Conversion is performed base 10 and leading sign characters are
permitted.s
- The array of bytes to be used.s
as an UInt256
type.java.lang.NumberFormatException
- if s
is not a valid
integer number.public byte[] toByteArray()
this
to an array of bytes.
The most significant byte will be returned in index zero.
The array will always be BYTES
bytes long, and
will be zero filled to suit the actual value.public byte[] toByteArray(byte[] bytes, int offset)
this
to an array of bytes.
The most significant byte will be returned in index offset
.
The array must be at least offset + BYTES
long.bytes
- The array to place the bytes in.offset
- The offset within the array to place the bytes.bytes
.public UInt256 add(UInt256 other)
other
to this
, returning the result.other
- The addend.UInt256
with the value this + other
.public UInt256 subtract(UInt256 other)
other
from this
, returning the result.other
- The subtrahend.UInt256
with the value this - other
.public UInt256 increment()
this
. Equivalent to this.add(Int256.ONE)
, but
faster.public UInt256 decrement()
this
. Equivalent to this.subtract(Int256.ONE)
, but
faster.public UInt256 multiply(UInt256 multiplicand)
this
by the specified multiplicand.multiplicand
- The multiplicand to multiply this
by.this * multiplicand
.public UInt256 divide(UInt256 divisor)
this
by the specified divisor.divisor
- The divisor to divide this
by.floor(this / divisor)
.java.lang.IllegalArgumentException
- if divisor
is zeropublic UInt256 remainder(UInt256 divisor)
this
by
the specified divisor.divisor
- The divisor to divide this
by.this / divisor
.public UInt256 pow(int exp)
this
exp
.exp
- the exponent to raise this
tothis
exp
public UInt256 shiftLeft()
this
left 1 bit. A zero bit is moved into the
leftmost bit.this
left one bit.public UInt256 shiftRight()
this
right 1 bit. A zero bit is moved into the
into the rightmost bit.this
right one bit.public UInt256 invert()
~this
.this
.public int compareTo(UInt256 n)
compareTo
in interface java.lang.Comparable<UInt256>
public Int128 getHigh()
public Int128 getLow()
public UInt256 or(UInt256 other)
this
with other
(this | other
).other
- The value to inclusive-or with this
.this | other
public UInt256 and(UInt256 other)
this
with other
(this & other
).other
- The value to and with this
.this & other
public UInt256 xor(UInt256 other)
this
with other
(this ^ other
).other
- The value to exclusive-or with this
.this ^ other
public int numberOfLeadingZeros()
long
value. Returns 128 if the
specified value has no one-bits in its two's complement representation,
in other words if it is equal to zero.
Note that this method is closely related to the logarithm base 2.
For all positive long
values x:
255 - numberOfLeadingZeros(x)
256 - numberOfLeadingZeros(x - 1)
long
value, or 256 if the value
is equal to zero.public boolean isZero()
true
if this
is zero.true
if this
is zero.public boolean isEven()
true
if this
is an even number.true
if this
is an even number.public boolean isOdd()
true
if this
is an odd number.true
if this
is an odd number.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(int radix)
If the radix is smaller than Character.MIN_RADIX
or larger than
Character.MAX_RADIX
, an IllegalArgumentException
is
thrown.
The characters of the result represent the magnitude of this
.
If the magnitude is zero, it is represented by a single zero character
'0'
; otherwise no leading zeros are output.
The following ASCII characters are used as digits:
0123456789abcdefghijklmnopqrstuvwxyz
If radix
is N, then the first N of these
characters are used as radix-N digits in the order shown,
i.e. the digits for hexadecimal (radix 16) are 0123456789abcdef
.radix
- the radix to use in the string representation.java.lang.IllegalArgumentException
- if radix
is less than
Character.MIN_RADIX
or greater than
Character.MAX_RADIX
.Character.MAX_RADIX
,
Character.MIN_RADIX