> ## 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.

# Kotlin Bitwise AND

In Kotlin, `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

Because `and` is an infix function, it can be invoked using either standard dot-notation or infix notation:

```kotlin theme={"dark"}
// Infix notation
val result = operand1 and operand2

// Standard function call notation
val result = operand1.and(operand2)
```

## Standard Library Signatures

The `and` 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.

```kotlin theme={"dark"}
class Int {
    public infix fun and(other: Int): Int
}

class Long {
    public infix fun and(other: Long): Long
}

class UInt {
    public infix fun and(other: UInt): UInt
}

class ULong {
    public infix fun and(other: ULong): ULong
}

class UByte {
    public infix fun and(other: UByte): UByte
}

class UShort {
    public infix fun and(other: UShort): UShort
}

class Boolean {
    public infix fun and(other: Boolean): Boolean
}
```

*Note: Kotlin does not define bitwise operations directly on **signed** 8-bit (`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 = 1`
* `1 and 0 = 0`
* `0 and 1 = 0`
* `0 and 0 = 0`

**Binary Evaluation Example:**
Evaluating `12 and 25` (showing the lowest 8 bits of the 32-bit `Int` for brevity):

```text theme={"dark"}
0000 1100  (12 in binary)
0001 1001  (25 in binary)

0000 1000  (Result: 8 in decimal)
```

## 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 to `true`. If the left-hand operand is `false`, the expression immediately returns `false` without evaluating the right side.

```kotlin theme={"dark"}
// Bitwise operation on Int
val bitwiseResult: Int = 5 and 3 

// Non-short-circuiting logical operation on Boolean
// Both sides are evaluated even if the left side is false
val booleanResult: Boolean = false and true 

// Short-circuiting logical operation on Boolean
// The right side is skipped because the left side is false
val logicalResult: Boolean = false && true
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Kotlin Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
