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

`Int` in Kotlin is a built-in numeric type representing a 32-bit (4-byte) signed two's complement integer. It is a member of the `kotlin` package, inherits from the abstract `Number` class, and implements the `Comparable<Int>` interface.

## Technical Specifications

* **Memory Size:** 32 bits (4 bytes)
* **Minimum Value (`Int.MIN_VALUE`):** -2,147,483,648 ($-2^{31}$)
* **Maximum Value (`Int.MAX_VALUE`):** 2,147,483,647 ($2^{31}-1$)
* **JVM Representation:** On the Java Virtual Machine, a non-nullable `Int` compiles directly to the Java primitive `int`.

## Syntax and Instantiation

Kotlin infers the `Int` type for any whole number literal that falls within the 32-bit range unless explicitly specified otherwise. Literals can be expressed in decimal, hexadecimal, or binary formats. Octal literals are not supported.

```kotlin theme={"dark"}
val inferredInt = 42                 // Type inferred as Int
val explicitInt: Int = 42            // Explicit type declaration
val hexInt: Int = 0x2A               // Hexadecimal literal
val binInt: Int = 0b101010           // Binary literal
val readableInt: Int = 1_000_000     // Underscores for readability
```

## Nullability and Boxing

Kotlin distinguishes between non-nullable (`Int`) and nullable (`Int?`) types. This distinction dictates how the compiler allocates memory on the JVM.

* **`Int`:** Compiled to the unboxed primitive `int` to optimize performance and memory.
* **`Int?`:** Compiled to the boxed wrapper class `java.lang.Integer`. Boxing also occurs when an `Int` is used as a generic type argument (e.g., `List<Int>`).

Because boxing allocates objects in memory, referential equality (`===`) behaves differently on nullable types compared to structural equality (`==`). Using `===` on non-nullable `Int` types is deprecated as identity equality is meaningless for unboxed primitives.

```kotlin theme={"dark"}
val unboxed: Int = 1000      // Primitive int
val boxed: Int? = 1000       // Boxed java.lang.Integer

val boxedA: Int? = 10000
val boxedB: Int? = 10000

// Structural equality compares the underlying values
println(boxedA == boxedB)  // true 

// Referential equality compares memory addresses of the boxed objects
println(boxedA === boxedB) // false (different object references in memory)
```

## Explicit Type Conversion

Kotlin does not support implicit widening conversions. An `Int` cannot be implicitly assigned to a `Long` or `Double` variable. Conversion must be handled explicitly using member functions inherited and overridden from the abstract `Number` class.

```kotlin theme={"dark"}
val baseInt: Int = 100

val toLong: Long = baseInt.toLong()
val toDouble: Double = baseInt.toDouble()
val toByte: Byte = baseInt.toByte() // Truncates the 24 most significant bits
```

## Bitwise Operations

Kotlin does not use standard C-style bitwise operators (e.g., `<<`, `>>`, `&`, `|`). Instead, bitwise operations on `Int` are performed using named functions. Binary bitwise operations are invoked as infix functions, whereas bitwise inversion (`inv()`) is a unary function that takes no arguments.

```kotlin theme={"dark"}
val a: Int = 0b0101
val b: Int = 0b0011

// Binary operations (Infix)
val shlResult = a shl 1    // Shift left (equivalent to Java <<)
val shrResult = a shr 1    // Shift right (equivalent to Java >>)
val ushrResult = a ushr 1  // Unsigned shift right (equivalent to Java >>>)
val andResult = a and b    // Bitwise AND (equivalent to Java &)
val orResult = a or b      // Bitwise OR (equivalent to Java |)
val xorResult = a xor b    // Bitwise XOR (equivalent to Java ^)

// Unary operation
val invResult = a.inv()    // Bitwise inversion (equivalent to Java ~)
```

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