In Kotlin,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.
and is a standard library member function—a regular identifier marked with the infix modifier—that performs a bitwise AND operation on specific integer types (Int, Long, UInt, ULong, UByte, UShort), as well as a non-short-circuiting logical AND operation on Boolean types.
For integers, it evaluates the binary representations of both operands, returning a value where each bit is 1 strictly if the corresponding bits in both operands are 1. For booleans, it evaluates both operands strictly, returning true only if both operands evaluate to true.
Unlike languages such as Java or C++ that use the & symbol for these operations, Kotlin implements them via named functions. Because and is not a hardcoded language keyword, it can even be used as a variable name without escaping, though it is primarily recognized as the standard bitwise/logical function.
Syntax
Becauseand is an infix function, it can be invoked using either standard dot-notation or infix notation:
Standard Library Signatures
Theand function is explicitly defined in the Kotlin Standard Library as a member function of specific primitive classes. The return type always matches the type of the operands.
Byte) or 16-bit (Short) integers. To perform a bitwise AND on these signed types, they must be explicitly promoted to Int first (e.g., byteVal.toInt() and 0xFF). Unsigned variants (UByte and UShort), however, fully support the and function natively.
Technical Mechanics: Integers
For integer types, the operation compares the operands bit-by-bit based on the following truth table:1 and 1 = 11 and 0 = 00 and 1 = 00 and 0 = 0
12 and 25 (showing the lowest 8 bits of the 32-bit Int for brevity):
Technical Mechanics: Booleans and Distinction from &&
When applied to Boolean types, and functions as a logical AND, but it differs fundamentally from the standard && operator in its evaluation strategy:
and(Non-short-circuiting): Evaluates both the left-hand and right-hand operands regardless of the left-hand operand’s value.&&(Short-circuiting): Evaluates the right-hand operand only if the left-hand operand evaluates totrue. If the left-hand operand isfalse, the expression immediately returnsfalsewithout evaluating the right side.
Master Kotlin with Deep Grasping Methodology!Learn More





