A case class representing an unsigned 64-bit integer.
This type uses a signed Long
underneath but provides operations that interpret the bits as an unsigned 64-bit value, giving access to the full range 0 to 2^64-1.
The underlying Long
storage means that values from 0 to Long.MAX_VALUE
(9,223,372,036,854,775,807) are stored as positive longs, while values from Long.MAX_VALUE + 1
to 2^64 - 1
are stored as negative longs using two's complement representation.
Example usage:
val small = Word64(1000L)
val large = Word64.fromUnsignedString("18446744073709551615") // 2^64 - 1
println(small.toUnsignedString) // "1000"
println(large.toUnsignedString) // "18446744073709551615"
println(large.toLong) // -1 (signed interpretation)
// Arithmetic works correctly with unsigned semantics
val sum = small + large
println(sum.toUnsignedString) // "999"
// Comparison uses unsigned semantics
println(large.compareUnsigned(small) > 0) // true
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
Bitwise AND operation.
Bitwise AND operation.
Value parameters
- other
-
the value to AND with
Attributes
- Returns
-
the result as Word64
Unsigned multiplication. Overflow wraps around.
Unsigned multiplication. Overflow wraps around.
Value parameters
- other
-
the value to multiply by
Attributes
- Returns
-
the product as Word64
Unsigned addition. Overflow wraps around.
Unsigned addition. Overflow wraps around.
Value parameters
- other
-
the value to add
Attributes
- Returns
-
the sum as Word64
Unsigned subtraction. Underflow wraps around.
Unsigned subtraction. Underflow wraps around.
Value parameters
- other
-
the value to subtract
Attributes
- Returns
-
the difference as Word64
Left shift operation.
Left shift operation.
Value parameters
- bits
-
number of bits to shift (only lower 6 bits are used)
Attributes
- Returns
-
the result as Word64
Arithmetic right shift operation (sign extends, but use >>> for unsigned).
Arithmetic right shift operation (sign extends, but use >>> for unsigned).
Value parameters
- bits
-
number of bits to shift (only lower 6 bits are used)
Attributes
- Returns
-
the result as Word64
Logical right shift operation (fills with zeros).
Logical right shift operation (fills with zeros).
Value parameters
- bits
-
number of bits to shift (only lower 6 bits are used)
Attributes
- Returns
-
the result as Word64
Bitwise XOR operation.
Bitwise XOR operation.
Value parameters
- other
-
the value to XOR with
Attributes
- Returns
-
the result as Word64
Compares this Word64 with another using unsigned comparison.
Compares this Word64 with another using unsigned comparison.
Value parameters
- other
-
the Word64 to compare with
Attributes
- Returns
-
negative if this < other, zero if equal, positive if this > other
Unsigned division.
Unsigned division.
Value parameters
- other
-
the divisor
Attributes
- Returns
-
the quotient as Word64
- Throws
-
ArithmeticException
if other is zero
Returns true if this Word64 represents a value greater than Long.MAX_VALUE.
Returns true if this Word64 represents a value greater than Long.MAX_VALUE.
Such values are stored as negative longs in two's complement.
Attributes
- Returns
-
true if the value exceeds Long.MAX_VALUE
Unsigned remainder (modulo).
Unsigned remainder (modulo).
Value parameters
- other
-
the divisor
Attributes
- Returns
-
the remainder as Word64
- Throws
-
ArithmeticException
if other is zero
Converts this Word64 to a BigInteger with unsigned interpretation.
Converts this Word64 to a BigInteger with unsigned interpretation.
This always returns a non-negative BigInteger representing the true unsigned value.
Attributes
- Returns
-
BigInteger representation of the unsigned value
Returns the hexadecimal string representation of this unsigned 64-bit value.
Returns the hexadecimal string representation of this unsigned 64-bit value.
Attributes
- Returns
-
hexadecimal string representation (without "0x" prefix)
Returns the underlying Long value (signed interpretation).
Returns the underlying Long value (signed interpretation).
For values > Long.MAX_VALUE, this returns a negative number due to two's complement representation.
Attributes
- Returns
-
the underlying Long value
Returns the string representation of this unsigned 64-bit value.
Returns the string representation of this unsigned 64-bit value.
Attributes
- Returns
-
string representation of the unsigned value
Bitwise NOT operation.
Bitwise NOT operation.
Attributes
- Returns
-
the bitwise complement as Word64
Inherited methods
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product