TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
shl (shift left) operator is an infix function in Kotlin that performs a bitwise left shift operation. It shifts the binary representation of the left-hand operand to the left by the number of bit positions specified by the right-hand operand.
During this operation, the vacated bit positions on the right (least significant bits) are filled with zeros, and the bits shifted beyond the left boundary (most significant bits) of the data type are discarded. Mathematically, x shl n is equivalent to multiplying x by , assuming no arithmetic overflow occurs.
Syntax and Signatures
In Kotlin, bitwise operators are not built-in language symbols (like<< in Java or C++) but are implemented as named infix functions. The shl function is defined for signed integers, unsigned integers, and java.math.BigInteger (via standard library extensions):
Bitwise Visualization
Technical Characteristics
1. Operand Masking To prevent shifting by a value greater than or equal to the bit-width of the type, Kotlin masks the right-hand operand (bitCount) at the hardware level for standard integer types:
- For
IntandUInt(32-bit): The shift distance is masked with31(binary11111). Therefore,x shl 32is equivalent tox shl 0, andx shl 33is equivalent tox shl 1. - For
LongandULong(64-bit): The shift distance is masked with63(binary111111). Therefore,y shl 64is equivalent toy shl 0.
shl function for smaller integer types like Byte, Short, UByte, or UShort, and it does not perform implicit widening conversions to resolve member or extension functions. Attempting to use shl directly on these types will result in a compiler error (Unresolved reference: shl). Explicit conversion to Int or UInt is strictly required before applying the operator.
shl shares the same precedence level as other bitwise operations (shr, ushr, and, or, xor). This precedence is lower than standard arithmetic operators (+, -, *, /) but higher than comparison operators (==, >, <).
Master Kotlin with Deep Grasping Methodology!Learn More





