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.
inv() function in Kotlin performs a bitwise inversion (also known as a bitwise NOT operation) on integer data types. It systematically flips every bit in the binary representation of the operand, converting all 0 bits to 1 and all 1 bits to 0.
Unlike languages such as Java or C++ that utilize the tilde (~) symbol for bitwise NOT operations, Kotlin implements bitwise operations as named functions. For signed integers, the inv() function is exclusively available on Int and Long.
Because Kotlin represents signed integers using two’s complement, applying the inv() function to a value x mathematically equates to -(x + 1). The sign bit is flipped along with the magnitude bits, which inherently changes the sign of the integer.
Handling Smaller Signed Types
Theinv() function is not a member of the signed Byte or Short classes. To perform a bitwise inversion on these smaller integral types, the value must be explicitly widened to an Int, inverted, and then narrowed back to the original type.
Unsigned Types
Kotlin also supportsinv() on all unsigned integer types (UByte, UShort, UInt, ULong). Unlike their signed counterparts, smaller unsigned types like UByte and UShort possess their own bitwise member functions and preserve their data types without requiring manual widening.
The bit-flipping mechanism remains identical, but because unsigned types do not use a sign bit or two’s complement for negative values, the resulting decimal interpretation differs significantly from signed types.
Master Kotlin with Deep Grasping Methodology!Learn More





