Skip to main content
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: 215-2^{15} or -32,768
  • Maximum: 21512^{15} - 1 or 32,767
These boundaries can be accessed programmatically via static properties:

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.

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.

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.

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 (&+, &-, &*).

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.
Tired of Poor Swift Skills? Fix That With Deep Grasping!Learn More