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

`Int8` is a value type in Swift that represents an 8-bit signed integer. It occupies exactly one byte of memory and stores values using two's complement binary representation, allowing it to represent both positive and negative whole numbers within a strictly defined 8-bit boundary.

## Value Range and Memory Footprint

Because it is constrained to 8 bits, `Int8` has a fixed mathematical range of $-2^7$ to $2^7 - 1$. Swift provides static properties to access these boundaries programmatically.

```swift theme={"dark"}
let lowestValue: Int8 = Int8.min   // -128
let highestValue: Int8 = Int8.max  // 127
let allocatedBits: Int = Int8.bitWidth // 8
```

## Type Safety and Instantiation

Swift enforces strict type safety and does not perform implicit type coercion between different integer sizes. An `Int8` cannot be directly assigned to or operated on with an `Int`, `Int16`, or `UInt8` without explicit initialization.

```swift theme={"dark"}
let defaultInt: Int = 100

// Implicit conversion fails at compile-time:
// let invalidByte: Int8 = defaultInt 

// Explicit initialization is required:
let validByte: Int8 = Int8(defaultInt)
```

If an explicit initialization is attempted with a value outside the `[-128, 127]` range, Swift will trigger a runtime crash. To handle potential out-of-bounds conversions safely, use the `exactly` parameter, which returns an optional:

```swift theme={"dark"}
let largeInt: Int = 200
let safeByte: Int8? = Int8(exactly: largeInt) // Returns nil
```

## Arithmetic and Overflow Behavior

Due to its narrow range, `Int8` is highly susceptible to arithmetic overflow. Standard arithmetic operators (`+`, `-`, `*`) check for overflow and will trigger a runtime trap (`EXC_BAD_INSTRUCTION`) if the result exceeds 8 bits.

To intentionally allow two's complement wrap-around behavior, Swift requires the use of explicit overflow operators (`&+`, `&-`, `&*`).

```swift theme={"dark"}
let maxBoundary: Int8 = 127

// Standard addition causes a runtime crash:
// let crash = maxBoundary + 1 

// Overflow addition wraps around to the minimum value:
let wrapped: Int8 = maxBoundary &+ 1 // -128
```

## Bitwise Operations

As a single-byte structure, `Int8` supports all standard Swift bitwise operators (`~`, `&`, `|`, `^`, `<<`, `>>`). When performing bitwise shifts on an `Int8`, the sign bit (the most significant bit) is preserved during right shifts (arithmetic shift).

```swift theme={"dark"}
let bitPattern: Int8 = 0b0000_1111 // 15 in decimal
let shiftedLeft: Int8 = bitPattern << 3 // 0b0111_1000 (120 in decimal)

let negativeBits: Int8 = -128 // 0b1000_0000
let shiftedRight: Int8 = negativeBits >> 1 // 0b1100_0000 (-64 in decimal, sign bit preserved)
```

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