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

# Swift Int32

`Int32` is a value type in Swift representing a fixed-width, 32-bit signed integer. It stores whole numbers using two's complement binary representation, allocating exactly 4 bytes of memory regardless of the underlying hardware architecture's word size.

## Value Range and Bounds

Because `Int32` is a signed 32-bit integer, it utilizes 1 bit for the sign and 31 bits for the magnitude. Its bounds are strictly defined and can be accessed via static properties:

```swift theme={"dark"}
let minValue: Int32 = Int32.min // -2,147,483,648 (-2^31)
let maxValue: Int32 = Int32.max //  2,147,483,647 (2^31 - 1)
```

## Initialization and Type Conversion

Swift is a strongly typed language and does not perform implicit type conversions. `Int32` cannot be implicitly cast to or from other integer types (like `Int`, `Int8`, or `Int64`), even if the value safely fits within the 32-bit range.

```swift theme={"dark"}
// Literal initialization
let explicitInt32: Int32 = 42

// Explicit conversion from standard Int
let standardInt: Int = 100
let convertedInt32 = Int32(standardInt)

// Explicit conversion from Int32 to Int64
let widenedInt = Int64(explicitInt32)
```

If a standard initialization attempt exceeds the 32-bit bounds, Swift triggers a runtime error. To handle potential out-of-bounds conversions safely, `Int32` provides an exact failable initializer:

```swift theme={"dark"}
let largeValue: Int64 = 5_000_000_000
let safeInt32 = Int32(exactly: largeValue) // Returns nil
```

## Memory and Bitwise Characteristics

As a type conforming to `FixedWidthInteger`, `Int32` exposes its binary characteristics directly. You can inspect its bit width and manipulate its memory representation using bitwise operators.

```swift theme={"dark"}
let bitCount = Int32.bitWidth // 32
    
let value: Int32 = 8
let leadingZeros = value.leadingZeroBitCount // 28
let trailingZeros = value.trailingZeroBitCount // 3
    
// Accessing the underlying two's complement bit pattern
let bitPattern: UInt32 = UInt32(bitPattern: -1) // 4294967295 (0xFFFFFFFF)
```

## Overflow Behavior

By default, arithmetic operations on `Int32` trap (crash) if the result exceeds the 32-bit bounds. To perform modular arithmetic that wraps around the 32-bit boundary without trapping, Swift provides specific masking operators (`&+`, `&-`, `&*`).

```swift theme={"dark"}
var max = Int32.max

// Standard addition: traps on overflow
// max += 1 // Fatal error: arithmetic overflow

// Masking addition: wraps to Int32.min
max = max &+ 1 // -2,147,483,648
```

## Protocol Conformances

`Int32` is implemented as a struct in the Swift Standard Library and conforms to a robust hierarchy of numeric and utility protocols, including:

* **`SignedInteger` & `FixedWidthInteger`**: Enabling bitwise operations, bit shifts, and sign-aware arithmetic.
* **`Hashable` & `Equatable`**: Allowing instances to be hashed for collection storage (like `Set` or `Dictionary` keys) and evaluated for equality.
* **`Comparable`**: Enabling sorting and relational operators (`<`, `>`, `<=`, `>=`).
* **`Codable`**: Supporting native serialization and deserialization to formats like JSON or Property Lists.
* **`Strideable`**: Allowing `Int32` to be used in ranges and loops with specific step increments.

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