> ## 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 Bitwise Right Shift

The `>>` operator in Swift is the bitwise right shift operator. It shifts the binary representation of an integer to the right by a specified number of bit positions, discarding the bits that are shifted beyond the least significant bit (LSB).

## Syntax

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

* `leftOperand`: The integer value whose bits will be shifted.
* `rightOperand`: The number of bit positions to shift.

## Behavior Based on Integer Type

Swift applies different bit-level mechanics depending on whether the left operand is an unsigned or signed integer type.

### Unsigned Integers (Logical Shift)

When applied to an unsigned integer (e.g., `UInt8`, `UInt32`), `>>` performs a **logical right shift**. The vacated bit positions at the most significant bit (MSB) end are strictly filled with zeros (`0`).

```swift theme={"dark"}
let unsignedValue: UInt8 = 0b11111111      // Decimal: 255
let shiftedUnsigned = unsignedValue >> 2   // Result: 0b00111111 (Decimal: 63)
```

### Signed Integers (Arithmetic Shift)

When applied to a signed integer (e.g., `Int8`, `Int`), `>>` performs an **arithmetic right shift**. To preserve the mathematical sign of the integer, the vacated bit positions are filled with the value of the original sign bit (the MSB).

* If the original value is positive (sign bit is `0`), it fills the vacated spaces with `0`s.
* If the original value is negative (sign bit is `1`), it fills the vacated spaces with `1`s.

```swift theme={"dark"}
// Positive signed integer (Sign bit is 0)
let positiveSigned: Int8 = 0b01111111      // Decimal: 127
let shiftedPositive = positiveSigned >> 2  // Result: 0b00011111 (Decimal: 31)

// Negative signed integer (Sign bit is 1, represented in two's complement)
let negativeSigned: Int8 = -8              // Binary: 0b11111000
let shiftedNegative = negativeSigned >> 2  // Result: 0b11111110 (Decimal: -2)
```

## Operand Constraints

The `rightOperand` must be greater than or equal to `0` and strictly less than the bit width of the `leftOperand`. If the right operand falls outside this range, Swift triggers a runtime crash. To safely handle shifts that may exceed the bit width without crashing, Swift provides the masking right shift operator (`&>>`).

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