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

`Int16` is a value type in Swift representing a signed 16-bit (2-byte) integer. It stores whole numbers using two's complement binary representation, allocating 1 bit for the sign and 15 bits for the magnitude.

## Value Range

Because it is a 16-bit signed integer, `Int16` has a strictly defined mathematical range:

* **Minimum:** $-2^{15}$ or `-32,768`
* **Maximum:** $2^{15} - 1$ or `32,767`

These boundaries can be accessed programmatically via static properties:

```swift theme={"dark"}
let lowestValue = Int16.min  // -32768
let highestValue = Int16.max // 32767
```

## Initialization and Syntax

Swift infers integer literals as the architecture-dependent `Int` type by default. To create an `Int16`, you must explicitly declare the type annotation or use an initializer.

```swift theme={"dark"}
// Type annotation
let explicitSixteen: Int16 = 15000

// Initialization via type conversion
let defaultInt = 42
let convertedSixteen = Int16(defaultInt)

// Hexadecimal, octal, and binary literals
let hexSixteen: Int16 = 0x7FFF // 32767
let binSixteen: Int16 = 0b0000_1111_1111_1111 // 4095
```

## Memory Layout

The memory footprint of `Int16` is guaranteed to be exactly 2 bytes across all platforms, regardless of whether the underlying architecture is 32-bit or 64-bit.

```swift theme={"dark"}
let byteSize = MemoryLayout<Int16>.size       // 2 bytes
let bitWidth = Int16.bitWidth                 // 16 bits
let alignment = MemoryLayout<Int16>.alignment // 2 bytes
```

## Type Safety and Conversion

Swift enforces strict type safety and does not perform implicit type conversions between different integer sizes. An `Int16` cannot be directly added to an `Int8`, `Int32`, `Int64`, or `Int` without explicit casting.

```swift theme={"dark"}
let a: Int16 = 1000
let b: Int8 = 10

// let result = a + b // Compile-time error: binary operator '+' cannot be applied to operands of type 'Int16' and 'Int8'
let result = a + Int16(b) // Valid: 'b' is explicitly promoted to Int16
```

## Overflow Behavior

By default, Swift arithmetic operators (`+`, `-`, `*`) trap and cause a runtime crash if an operation results in a value outside the `Int16` range. To perform modulo arithmetic that truncates the result instead of crashing, you must use Swift's overflow operators (`&+`, `&-`, `&*`).

```swift theme={"dark"}
var maxVal = Int16.max

// maxVal += 1 // Runtime crash: arithmetic overflow

// Two's complement wrap-around
let wrappedVal = maxVal &+ 1 // Evaluates to -32768 (Int16.min)
```

## Protocol Conformances

As a fundamental numeric type, `Int16` conforms to several standard library protocols that dictate its behavior:

* `FixedWidthInteger`: Guarantees a static bit width and provides bitwise operations.
* `SignedInteger`: Indicates the type can represent both positive and negative values.
* `Hashable` & `Equatable`: Allows `Int16` to be used as dictionary keys and compared for equality.
* `Codable`: Supports native serialization and deserialization.

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