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

`Int64` is a value type in the Swift Standard Library representing a fixed-width, 64-bit signed integer. It allocates exactly 8 bytes of memory to store numerical values using two's complement binary representation, allowing it to represent both positive and negative whole numbers within a strictly defined, immutable range.

## Memory and Bounds

As a 64-bit signed integer utilizing two's complement representation, the most significant bit (MSB) functions as the sign bit (`0` for positive, `1` for negative). For positive values, the lower 63 bits represent the binary magnitude. For negative values, the bit pattern represents the bitwise NOT of the magnitude plus one. This encoding ensures a single representation of zero and allows the arithmetic logic unit (ALU) to perform addition and subtraction without distinguishing between positive and negative operands.

* **Minimum Value:** $-2^{63}$ (`-9,223,372,036,854,775,808`)
* **Maximum Value:** $2^{63} - 1$ (`9,223,372,036,854,775,807`)

You can access these boundaries programmatically using static properties:

```swift theme={"dark"}
let lowestValue: Int64 = Int64.min
let highestValue: Int64 = Int64.max
```

## Type Safety and Conversion

Swift enforces strict type safety. `Int64` is a distinct type from the platform-dependent `Int`. Even on 64-bit architectures (where `Int` is also 64 bits wide), the compiler treats `Int` and `Int64` as entirely separate types. Implicit casting is not permitted; you must explicitly initialize an `Int64` when converting from other numeric types.

```swift theme={"dark"}
let platformInt: Int = 42
let explicitInt64: Int64 = 42

// let typeMismatch: Int64 = platformInt // Compiler Error: Cannot convert value of type 'Int' to specified type 'Int64'

let convertedInt64 = Int64(platformInt)  // Valid explicit conversion
```

## Protocol Conformances

`Int64` is implemented as a struct and conforms to a robust hierarchy of numeric protocols, which dictate its available operations:

* **`FixedWidthInteger`**: Guarantees a specific bit width and provides endianness conversions (`bigEndian`, `littleEndian`) and bitwise operations.
* **`SignedInteger`**: Requires the type to represent both positive and negative values.
* **`BinaryInteger`**: Provides the foundation for all integer types, enabling bit-shift operations (`<<`, `>>`) and quotient/remainder division.
* **`Hashable`, `Equatable`, `Comparable`**: Allows `Int64` to be used as dictionary keys, compared using standard relational operators (`==`, `<`, `>`), and sorted.

## Overflow and Underflow Behavior

By default, Swift arithmetic operators (`+`, `-`, `*`) trap (trigger a runtime crash) if an operation exceeds the bounds of `Int64`. To perform modulo arithmetic that wraps around the bounds instead of crashing, `Int64` supports Swift's overflow operators (`&+`, `&-`, `&*`).

Note that the compiler performs constant folding on literal arithmetic. To observe a runtime trap rather than a compile-time error, the overflow must occur during runtime evaluation:

```swift theme={"dark"}
var currentVal: Int64 = Int64.max

// currentVal += 1 // Runtime execution trap (Overflow)

let wrappedVal: Int64 = currentVal &+ 1 // Wraps to Int64.min (-9,223,372,036,854,775,808)
```

## Bitwise Operations

As a `FixedWidthInteger`, `Int64` supports direct bit manipulation. Operations are applied across all 64 bits.

```swift theme={"dark"}
let a: Int64 = 0b1010_1010
let b: Int64 = 0b0101_0101

let bitwiseAnd = a & b  // 0b0000_0000
let bitwiseOr  = a | b  // 0b1111_1111
let bitwiseXor = a ^ b  // 0b1111_1111
let bitShift   = a << 2 // 0b10_1010_1000
```

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