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 TypeMethodDescriptionstatic DittoUIntfromIntData(int data) Creates an unsigned integer from raw 32-bit data.static DittoUIntfromLong(long value) Creates an unsigned integer from alongvalue.intReturns the raw 32-bit representation as a signed Javaint.longtoLong()Returns this unsigned integer as a signedlongvalue.
-
Method Details
-
toLong
long toLong()Returns this unsigned integer as a signed
longvalue.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 returnedintwill be negative due to Java's signed integer representation. The bit pattern, not the numerical value, is preserved.Note: Negative
intvalues 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
Creates an unsigned integer from a
longvalue.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- thelongvalue to convert.- Returns:
- a
DittoUIntrepresenting the least significant 32 bits of the value.
-
fromIntData
Creates an unsigned integer from raw 32-bit data.
This interprets the provided
intas a raw bit pattern, not as a signed value. For example,fromIntData(-1)creates aDittoUIntrepresenting 232-1.- Parameters:
data- the 32-bit data pattern as a signedint.- Returns:
- a
DittoUIntrepresenting the unsigned interpretation of the data.
-