Interface DittoUInt


public interface DittoUInt

Represents an unsigned 32-bit integer.

Java does not have native unsigned integer types, so this interface provides a way to work with unsigned 32-bit integers in the range [0, 232-1]. Values can be converted to/from Java's signed long type for arithmetic operations or stored as raw 32-bit data in a signed int.

  • Method Summary

    Modifier and Type
    Method
    Description
    static DittoUInt
    fromIntData(int data)
    Creates an unsigned integer from raw 32-bit data.
    static DittoUInt
    fromLong(long value)
    Creates an unsigned integer from a long value.
    int
    Returns the raw 32-bit representation as a signed Java int.
    long
    Returns this unsigned integer as a signed long value.
  • Method Details

    • toLong

      long toLong()

      Returns this unsigned integer as a signed long value.

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

      Returns:
      the unsigned integer value as a long, guaranteed to be non-negative.
    • toIntData

      int toIntData()

      Returns the raw 32-bit representation as a signed Java int.

      This method returns the underlying bit pattern without interpretation. For unsigned values greater than Integer.MAX_VALUE, the returned int will be negative due to Java's signed integer representation. The bit pattern, not the numerical value, is preserved.

      Note: Negative int values returned by this method do not represent negative numbers—they represent unsigned values > 231-1.

      Returns:
      the 32-bit data as a signed int.
    • fromLong

      static DittoUInt fromLong(long value)

      Creates an unsigned integer from a long value.

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

      Parameters:
      value - the long value to convert.
      Returns:
      a DittoUInt representing the least significant 32 bits of the value.
    • fromIntData

      static DittoUInt fromIntData(int data)

      Creates an unsigned integer from raw 32-bit data.

      This interprets the provided int as a raw bit pattern, not as a signed value. For example, fromIntData(-1) creates a DittoUInt representing 232-1.

      Parameters:
      data - the 32-bit data pattern as a signed int.
      Returns:
      a DittoUInt representing the unsigned interpretation of the data.