Interface DittoULong
Represents an unsigned 64-bit integer.
Java does not have native unsigned integer types, so this interface provides
a way to work with unsigned 64-bit integers in the range [0, 264-1].
Values can be converted to/from BigInteger for arithmetic operations or
stored as raw 64-bit data in a signed long.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull DittoULongfromBigInteger(@NonNull BigInteger bigInteger) Creates an unsigned integer from aBigInteger.static @NonNull DittoULongfromLongData(long data) Creates an unsigned integer from raw 64-bit data.@NonNull BigIntegerReturns this unsigned integer as aBigInteger.longReturns the raw 64-bit representation as a signed Javalong.
-
Method Details
-
toBigInteger
@NonNull BigInteger toBigInteger()Returns this unsigned integer as a
BigInteger.The returned
BigIntegeris always non-negative and represents the true numerical value of this unsigned 64-bit integer.- Returns:
- a
BigIntegerrepresenting the unsigned integer value.
-
toLongData
long toLongData()Returns the raw 64-bit representation as a signed Java
long.This method returns the underlying bit pattern without interpretation. For unsigned values greater than
Long.MAX_VALUE, the returnedlongwill be negative due to Java's signed integer representation. The bit pattern, not the numerical value, is preserved.Note: Negative
longvalues returned by this method do not represent negative numbers—they represent unsigned values > 263-1.- Returns:
- the 64-bit data as a signed
long.
-
fromBigInteger
Creates an unsigned integer from a
BigInteger.Only the least significant 64 bits of the
BigIntegerare used. If the value is non-negative and less than 264, the resulting unsigned integer represents the same numerical value.- Parameters:
bigInteger- theBigIntegerto convert.- Returns:
- a
DittoULongrepresenting the least significant 64 bits of the value.
-
fromLongData
Creates an unsigned integer from raw 64-bit data.
This interprets the provided
longas a raw bit pattern, not as a signed value. For example,fromLongData(-1L)creates aDittoULongrepresenting 264-1.- Parameters:
data- the 64-bit data pattern as a signedlong.- Returns:
- a
DittoULongrepresenting the unsigned interpretation of the data.
-