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.
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: or
-32,768 - Maximum: or
32,767
Initialization and Syntax
Swift infers integer literals as the architecture-dependentInt type by default. To create an Int16, you must explicitly declare the type annotation or use an initializer.
Memory Layout
The memory footprint ofInt16 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. AnInt16 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: AllowsInt16to be used as dictionary keys and compared for equality.Codable: Supports native serialization and deserialization.
Master Swift with Deep Grasping Methodology!Learn More





