Skip to main content
Int32 is a value type in Swift representing a fixed-width, 32-bit signed integer. It stores whole numbers using two’s complement binary representation, allocating exactly 4 bytes of memory regardless of the underlying hardware architecture’s word size.

Value Range and Bounds

Because Int32 is a signed 32-bit integer, it utilizes 1 bit for the sign and 31 bits for the magnitude. Its bounds are strictly defined and can be accessed via static properties:

Initialization and Type Conversion

Swift is a strongly typed language and does not perform implicit type conversions. Int32 cannot be implicitly cast to or from other integer types (like Int, Int8, or Int64), even if the value safely fits within the 32-bit range.
If a standard initialization attempt exceeds the 32-bit bounds, Swift triggers a runtime error. To handle potential out-of-bounds conversions safely, Int32 provides an exact failable initializer:

Memory and Bitwise Characteristics

As a type conforming to FixedWidthInteger, Int32 exposes its binary characteristics directly. You can inspect its bit width and manipulate its memory representation using bitwise operators.

Overflow Behavior

By default, arithmetic operations on Int32 trap (crash) if the result exceeds the 32-bit bounds. To perform modular arithmetic that wraps around the 32-bit boundary without trapping, Swift provides specific masking operators (&+, &-, &*).

Protocol Conformances

Int32 is implemented as a struct in the Swift Standard Library and conforms to a robust hierarchy of numeric and utility protocols, including:
  • SignedInteger & FixedWidthInteger: Enabling bitwise operations, bit shifts, and sign-aware arithmetic.
  • Hashable & Equatable: Allowing instances to be hashed for collection storage (like Set or Dictionary keys) and evaluated for equality.
  • Comparable: Enabling sorting and relational operators (<, >, <=, >=).
  • Codable: Supporting native serialization and deserialization to formats like JSON or Property Lists.
  • Strideable: Allowing Int32 to be used in ranges and loops with specific step increments.
Tired of Poor Swift Skills? Fix That With Deep Grasping!Learn More