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.
UByte is an unsigned 8-bit integer type in Kotlin that represents values from 0 to 255, inclusive. It is implemented as an inline class (specifically, a value class) that wraps a standard signed 8-bit Byte to provide unsigned semantics without the runtime overhead of object allocation.
Technical Specifications
- Memory Footprint: 8 bits (1 byte)
- Minimum Value:
UByte.MIN_VALUE(0) - Maximum Value:
UByte.MAX_VALUE(255) - Type Hierarchy: Implements
Comparable<UByte>
Instantiation and Syntax
UByte instances are created using the u or U literal suffix, or via explicit conversion functions from other numeric types.
JVM Representation and Boxing
On the JVM,UByte is compiled down to a primitive byte. The Kotlin compiler enforces unsigned constraints at compile time and emits the necessary bytecode (such as bitwise masking) to simulate unsigned operations.
Boxing (allocating a heap object) only occurs when UByte is used in contexts requiring an object reference:
- When declared as a nullable type (
UByte?). - When used as a generic type argument (e.g.,
List<UByte>).
Operations and Type Promotion
Standard arithmetic operations are supported. However, to prevent silent overflows, arithmetic operations (+, -, *, /, %) between two UByte values automatically promote the result to a UInt.
Bitwise operations (and, or, xor) and bitwise shift operators (shl, shr) are not defined directly on UByte. To perform these operations, the value must be explicitly converted to a larger unsigned type (UInt or ULong) first.
Kotlin does not define the ushr (unsigned shift right) operator for any unsigned types. Because unsigned types inherently do not sign-extend, the standard shr operator already performs a logical (unsigned) shift, making ushr unnecessary. The bitwise inversion function (inv()) is the only bitwise operation supported directly on UByte.
Arrays
Kotlin providesUByteArray to represent an array of unboxed unsigned bytes. Under the hood, UByteArray is an inline class wrapping a standard ByteArray, ensuring that no boxing occurs for the elements within the array.
Master Kotlin with Deep Grasping Methodology!Learn More





