Interface DittoULong


public 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 Details

    • toBigInteger

      @NonNull BigInteger toBigInteger()

      Returns this unsigned integer as a BigInteger.

      The returned BigInteger is always non-negative and represents the true numerical value of this unsigned 64-bit integer.

      Returns:
      a BigInteger representing 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 returned long will be negative due to Java's signed integer representation. The bit pattern, not the numerical value, is preserved.

      Note: Negative long values 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

      static @NonNull DittoULong fromBigInteger(@NonNull BigInteger bigInteger)

      Creates an unsigned integer from a BigInteger.

      Only the least significant 64 bits of the BigInteger are used. If the value is non-negative and less than 264, the resulting unsigned integer represents the same numerical value.

      Parameters:
      bigInteger - the BigInteger to convert.
      Returns:
      a DittoULong representing the least significant 64 bits of the value.
    • fromLongData

      static @NonNull DittoULong fromLongData(long data)

      Creates an unsigned integer from raw 64-bit data.

      This interprets the provided long as a raw bit pattern, not as a signed value. For example, fromLongData(-1L) creates a DittoULong representing 264-1.

      Parameters:
      data - the 64-bit data pattern as a signed long.
      Returns:
      a DittoULong representing the unsigned interpretation of the data.