Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
ULong is an unsigned 64-bit integer type in Kotlin that represents values from 0 to 18,446,744,073,709,551,615 (). It is implemented as a value class (specifically, a @JvmInline value class) that wraps a standard signed 64-bit Long. This design provides unsigned arithmetic and bitwise semantics while avoiding object allocation overhead at runtime, compiling down to a primitive long on the JVM in unboxed contexts.
Instantiation and Syntax
ULong literals are defined by appending the u (or U) and L suffixes to an integer literal.
ULong using extension functions:
Memory Representation and Boxing
BecauseULong is an inline value class, the Kotlin compiler treats it as a primitive long during execution whenever possible. However, boxing occurs when ULong is used in generic contexts, nullable types, or as an interface implementation.
Operations and Semantics
ULong supports standard arithmetic (+, -, *, /, %) and comparison (<, >, ==) operators. The Kotlin compiler translates these into unsigned operations at the bytecode level (e.g., utilizing java.lang.Long.divideUnsigned on the JVM).
ULong supports standard bitwise operations (and, or, xor, inv). However, bitwise shift semantics differ from signed Long:
shr(Shift Right): Performs a logical shift (zero-fill), whereasshron a signedLongperforms an arithmetic shift (sign-extend).ushr(Unsigned Shift Right): Not available onULong, asshralready provides the logical shift behavior.shl(Shift Left): Functions identically to signed integers.
ULongArray
To prevent boxing overhead when working with collections ofULong data, Kotlin provides ULongArray. At the JVM level, ULongArray is backed by a primitive long[], ensuring contiguous memory allocation and zero boxing per element.
Type Constraints and Interoperability
- Widening Conversions: Kotlin does not implicitly widen types. A
UIntcannot be passed to a function expecting aULongwithout an explicit.toULong()cast. - Java Interoperability: Because Java lacks native unsigned types,
ULongis exposed to Java code as a signedlong. Functions acceptingULongin Kotlin will undergo name mangling in the generated JVM bytecode to prevent signature collisions with functions accepting signedLong.
Master Kotlin with Deep Grasping Methodology!Learn More





