> ## 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 Overflow Addition

The `&+` operator is Swift's overflow addition operator. It performs integer addition while explicitly allowing the result to exceed the memory bounds of the underlying integer type, silently wrapping around the type's limits instead of triggering a runtime trap.

In Swift, standard arithmetic operators (like `+`) are safe by default; if an operation results in a value outside the representable range of the type, the program halts with an overflow error. The `&+` operator bypasses this safety check, utilizing two's complement arithmetic to truncate the bits that exceed the available bit width.

## Syntax

```swift theme={"dark"}
let result = leftOperand &+ rightOperand
```

*Note: Both operands must be of the exact same integer type.*

## Overflow Behavior

The wrapping behavior differs mechanically depending on whether the integer type is unsigned or signed.

### Unsigned Integers

When an unsigned integer exceeds its maximum representable value, it wraps around to zero and continues counting upward.

```swift theme={"dark"}
let maxUnsigned: UInt8 = 255 // Binary: 11111111
let wrappedUnsigned = maxUnsigned &+ 1
// Result: 0 (Binary: 00000000)
```

**Mechanism:** `255 + 1` requires 9 bits (`100000000`). The `&+` operator discards the 9th bit (the overflow bit), leaving the 8-bit representation of `0`.

### Signed Integers

When a signed integer exceeds its maximum representable value, the overflow alters the sign bit, causing the value to wrap around to the type's minimum representable (negative) value.

```swift theme={"dark"}
let maxSigned: Int8 = 127 // Binary: 01111111
let wrappedSigned = maxSigned &+ 1
// Result: -128 (Binary: 10000000)
```

**Mechanism:** `127 + 1` results in `10000000`. In an 8-bit signed integer using two's complement, the most significant bit is the sign bit. Setting it to `1` changes the value to `-128`.

## Compound Assignment

The overflow addition operator can also be used as a compound assignment operator (`&+=`), which mutates the left-hand operand in place.

```swift theme={"dark"}
var counter: UInt8 = 255
counter &+= 1 
// counter is now 0
```

## Related Operators

The `&+` operator is part of a specific family of overflow operators in Swift designed to handle bitwise truncation, which also includes:

* `&-` (Overflow Subtraction)
* `&*` (Overflow Multiplication)

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